Unicode support in C++0x

后端 未结 3 1657
太阳男子
太阳男子 2021-01-04 03:17

I\'m trying to use new unicode characters in C++0x. So I wrote sample code:

#include 
#include 
int main()
{
    std::u32string          


        
3条回答
  •  耶瑟儿~
    2021-01-04 03:42

    Unicode string literals support began in GCC 4.5. Maybe that's the problem.

    [edit]

    After some digging I've found that streams for this new unicode literals are described in N2035 and it was included in a draft of the standard. According to this document you need u32ofstream to output you string but this class is absent in GCC 4.5 C++0x library.

    As a workaround you can use ordinary fstream:

    std::ofstream fout2("output2.txt", std::ios::out | std::ios::binary);
    fout2.write((const char *)str.c_str(), str.size() * 4);
    

    This way I've output your string in UTF-32LE on my Intel machine (which is little-endian).

    [edit]

    I was a little bit wrong about the status of u32ofstream: according to the latest draft on the The C++ Standards Committee's web site you have to use std::basic_ofstream as you did. This class would use codecvt class (see end of §27.9.1.1) which has to be implemented in the standard library (search codecvt in the document), but it's not available in GCC 4.5.

提交回复
热议问题