//读取filename文件的内容到wstring
bool ReadFileTowstring(const char *szfile, wstring &content)
{
CString filename(szfile);
//存储读取的wstring
content.clear();
wchar_t linex[4096];
FILE * file;
//格式化filename为wchar_t *
wchar_t *wc = new wchar_t[filename.GetLength()];
wchar_t *wmode = wc;
swprintf(wc,L"%S",filename);
//读取utf-8编码的文件
file=_wfopen(wc,L"rt+,ccs=UTF-8");
locale loc("");
wcout.imbue(loc);
//while (!feof(file))
while(fgetws(linex,4096,file))
{
//fgetws(linex,4096,file);
//wstring linew = linex;
//content+=linew;
content += wstring(linex);
}
fclose(file);
return true;
}
读取filename文件的内容到wstring
最新推荐文章于 2023-03-09 19:01:17 发布