Thursday, June 23, 2011

A bit of C++0x new raw and unicode string literals

C++x0 introduced new string literals: starting with 'u8', 'u', 'U' and 'R'.
'u8' is for utf-8
'u' is for utf-16
'U' is for utf-32
'R' is for raw strings
(Also you can combine those: u8R, uR and UR
#include 
#include 

int main()
{
    std::string old = "c:\\test\\test";
    std::string raw = R"(c:\test\test)";
    std::string utf8 = u8"This is a Unicode Character: \u0160."; 

    std::cout << "old literal: " << old << std::endl;
    std::cout << "new raw literal: " << raw << std::endl;
    std::cout << "new utf-8 literal: " << utf8 << std::endl;

    return 0;
}
Output:
old literal: c:\test\test
new raw literal: c:\test\test
new utf-8 literal: This is a Unicode Character: Š.
Read more here...