Is this a BIG bug in all VC++ versions? About Unicode CR/LF translation.

X

xmllmx

4 lines of code are worth a thousand words.

wofstream fout("test.txt", ios::eek:ut|ios::trunc);
fout.imbue(locale(locale::classic(), new codecvt_utf16<wchar_t,
0x10FFFFUL, little_endian>)); // UTF-16LE
fout << L'\n';
fout.close();

// Compiled with VC++ 2010 that supports C++0x.

Please note that the file is opened in unicode text mode. Because
fout.close() will automatically replace every LF with CR-LF, So,
test.txt now should hold 4 bytes which are 0x0D, 0x00, 0x0A, 0x00.

However, test.txt should just hold 3 bytes which are 0x0D, 0x0A, 0x00.
Notepad will fail to recognize this file.

Is this really a BIG bug?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,089
Latest member
Ketologenic

Latest Threads

Top