How do I get STL std::string to work with unicode on windows?

前端 未结 9 2113
猫巷女王i
猫巷女王i 2021-02-04 13:29

At my company we have a cross platform(Linux & Windows) library that contains our own extension of the STL std::string, this class provides all sort of functionality on top

9条回答
  •  猫巷女王i
    2021-02-04 14:10

    It really platform dependant, Unicode is headache. Depends on which compiler you use. For older ones from MS (VS2010 or older), you would need use API described in MSDN

    for VS2015

    std::string _old = u8"D:\\Folder\\This \xe2\x80\x93 by ABC.txt"s;
    

    according to their docs. I can't check that one.

    for mingw, gcc, etc.

    std::string _old = u8"D:\\Folder\\This \xe2\x80\x93 by ABC.txt";
    std::cout << _old.data();
    

    output contains proper file name...

提交回复
热议问题