How do I store Unicode characters in a text file in separate lines using C++? I tried using \n
and \r
; also with their hex
values. But, in the .txt
file \n
and \r
are read as garbage values.
Here is the code snippet:
{
std::wofstream wof;
wof.imbue(std::locale(std::locale::empty(), new std::codecvt_utf16<wchar_t,
0x10ffff, std::generate_header>));
wof.open(L"file3.txt");
wof << L"Test.\x263a \x263c \x263d \x263e A:B:C, 我一个人来 人人都爱喝可乐。 " << endl;
wof << L"\n Another test. \x002c \x263a \263e" << endl;
wof << L"\n 我一个人来。 一个人 我一个人来 人人都爱喝可乐。" << endl;
wof << L" Test \x263a \x263c \x263d \x263e 我一个人来 人人都爱喝可乐。 " << endl;
wof << L"\n 我一个人来 人人都爱喝可乐。" << endl;
}