Outputting 'wchar_t*' to an 'ofstream'

孤人 提交于 2020-01-29 06:02:25

问题


I want to output a text to a file via two pointers that I have declared:

wchar_t   *Col1="dsffsd", *Col2="sdfsf";

Here is what I have tried:

std::ofstream fout;
fout.open(NativeDatabasePathHist);
fout<<"testing";
fout<<" "<<Col1<<" "<<Col2;
fout.close();

And here is what I am getting:

testing 113 113

Why is it that when I print Col1 and Col2, I am getting numbers instead of strings?


回答1:


First, use std::wofstream instead of std::ofstream.

Also, use the L prefix on your text string to indicate that your text is wide character text:

wchar_t   *Col1=L"dsffsd"



回答2:


Since you have written it using wide characters (wchar_t), you need to look at the resulting file with something that understands wide characters.



来源:https://stackoverflow.com/questions/12889405/outputting-wchar-t-to-an-ofstream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!