0

I am using Boost Ofstream for Unicode std::string output. I am stuck with using the right locale (Boost)/ Encoding to support all the languages (in all the Unicode versions upto 6.3). The code is targeted to compile on both VS2010 and GCC 4.8

loc::generator gen;
std::locale _loc= gen.generate("en_US.utf-8"); // use the right POSIX locale/ encoding, 
                                              // to support different versions of Unicode 
                                             // and with different compilers
std::string str = "my unicode string";
boost::filesystem::ofstream _file("my file.txt");
_file.imbue(_loc);
_file<<str;

I am trying to understand the different Unicode versions, encodings, locale support from different compilers.

ProgramCpp
  • 1,280
  • 2
  • 15
  • 26
  • What is the question? – R. Martinho Fernandes Nov 12 '13 at 13:03
  • How to write unicode strings to a file in Windows(VS2010) and Linux (GCC)? – ProgramCpp Nov 13 '13 at 09:02
  • Usually you can just write the bytes directly into it (as does the sample code in the answer). You need to be way more specific about what your problem is. – R. Martinho Fernandes Nov 13 '13 at 09:06
  • The above code writes "Tésting!" but not "ऐकअ". It writes "???" instead.Is the problem with the compiler setting or std::string or locale for Boost? Can you explain if the POSIX locale format ([language[_territory][.codeset][@modifier]]) have any effect for different unicode script. – ProgramCpp Nov 13 '13 at 11:19
  • Bytes. Bytes. Look at the bytes. Don't look at it through a flawed lens like a text editor. You cannot know if the editor is interpreting the data correctly. – R. Martinho Fernandes Nov 13 '13 at 12:38
  • For the string "ऐकअ", the Bytes read 0x22 3F 3F 3F 22 which is ASCII equivalent of "???". Whereas the Unicode Byte values as per Unicode 6.3 are ऐ : 0x090E;क : 0x0915;अ : 0x0905.i.e, 6 Bytes in total. The problem is with string literals – ProgramCpp Nov 14 '13 at 10:30
  • check [this answer](http://stackoverflow.com/a/1275260/2508038). also, use wofstream instead of ofstream – ProgramCpp Dec 27 '13 at 10:31

0 Answers0