unicode - Typographic apostrophe + wide string literal broke my wofstream (C++) -
I had to face some strange behavior in dealing with inauspicious typographic apoprophies (') - Typewriter apostropha ('. Epostroffefream breaks down.
This code works
offstream file ("test.txt"); file & lt; & lt ; "A'b"; file.close (); ==> A-B
This code works
< Code> wofstream file ("test.txt"); File This code fails
wofstream file ("test.txt"); File "A'B"; File.close ();
==> A
This code fails ...
wstring test = l "A'b"; Wofstream file ("test.txt"); File
==> A
Any ideas?
Before you can use wofstream, the "enabled" locale should be: < / P>
std :: locale :: global (std :: locale ()); // local support support wofstream file ("test.txt"); File & lt; & Lt; L "A'B"; So if you have the system locale en_US.UTF-8 then the file test.txt will contain UF 8 encoded data ( 4 bye), if you have the system locale en_US.ISO8859-1 , then it must be encoded as 8 bit encoding (3 bytes), as long as the ISO 8859-1 Does not miss the character
wofstream file ("test.txt"); File & lt; & Lt; "A'b"; File.close (); This code works because "A'B" is actually a utf-8 string and you can use utf-8 string byte to file a byte Save.
Note: I think that you are using POSIs like OS, and you have default location which is different from "C" which is the default locale.
Comments
Post a Comment