Here is the code:
std::ofstream f("file1.txt");
f<<"123"<<std::endl<<"456";
std::wstringstream s;
s<<L"123"<<std::endl<<L"456";
s<<L"123"<<L"\n"<<L"456";
s<<"123"<<WCHAR(13)<<WCHAR(10)<<"456";
HANDLE h =CreateFileW(L"file2.txt", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
ULONG l;
WriteFile(h, s.str().c_str(), s.str().length() * 2, &l, NULL);
In the case of (* 1) there is a newline, in (* 2) and (* 3) I do not see a newline in file2.txt. There is a new line in (* 3). I use notepad.exeto view. There is no byte in the hex editor 0x0D, only 0x0A.
How to correctly put a new line in a text file in Unicode? Thank.
source
share