用sscanf s按指定格式讀檔案,出現亂碼

2021-10-02 22:28:52 字數 1194 閱讀 8894

我(小白學c/c++兩個半月)只是想記錄我的一些bug,大神勿進

讀的檔案:

**如下:

#include

#include

#include

#include

#include

using namespace std;

int main()

sscanf_s(line.c_str(), "name:%s age:%d", name,

sizeof(name), &age);

cout << "姓名:" << name << "\t\t\t年齡:" << age << endl;

}infile.close();

system("pause");

return 0;}

執行正確結果:

//《以下是亂碼的情況》

**如下:

#include

#include

#include

#include

#include

using namespace std;

int main()

**sscanf_s(line.c_str(), "姓名:%s 年齡:%d", name,

sizeof(name), &age);**

cout << "姓名:" << name << "\t\t\t年齡:" << age << endl;

}infile.close();

system("pause");

return 0;執行結果:

原因是:

**與文字不符合:

sscanf_s(line.c_str(), 「姓名:%s 年齡:%d」, name,

時間按指定格式轉換

推薦閱讀 一。把秒數轉換成 00 00 00 大於一天顯示 1天2時local function second2dhms second if second 0 then return0,0,0,0 end local d math.floor second 86400 second second d...

時間按指定格式轉換

推薦閱讀 一。把秒數轉換成 00 00 00 大於一天顯示 1天2時local function second2dhms second if second 0 then return 0,0,0,0 endlocal d math.floor second 86400 second second d...

JavaScript按指定格式輸出時間

按所給的時間格式輸出指定的時間 格式說明 對於 2014.09.05 13 14 20 yyyy 年份,2014 yy 年份,14 mm 月份,補滿兩位,09 m 月份,9 dd 日期,補滿兩位,05 d 日期,5 hh 24制小時,補滿兩位,13 h 24制小時,13 hh 12制小時,補滿兩位,...