Here is my simple C/C++ program:
int main() {
FILE* f = fopen("MyTest.log", "w");
fprintf(f, "%ls\n", L"abc");
fprintf(f, "%ls\n", L"您好"); // Data from a different locale
fprintf(f, "%ls\n", L"def");
fclose(f);
return 0;
}
When I run this program, the generated file does not contain the middle line at all. It appears fprintf
simply returns back once it detects a different character set in the passed parameter.
I have tested this program on Windows as well as Ubuntu. The same problem at both the places.
Browsing the forum, I found a few hints such as using _setmode() and fwprintf. However, if possible, I would like to stick to fprintf(). Also, my code needs to work on Windows as well as Linux.
Does anyone know to achieve this? Regards.