What encoding does std::string.c_str() use?

后端 未结 2 1305
春和景丽
春和景丽 2020-11-30 06:49

I am trying to convert a C++ std::string to UTF-8 or std::wstring without losing information (consider a string that contains non-ASCII characters)

相关标签:
2条回答
  • 2020-11-30 06:56

    std::string per se uses no encoding -- it will return the bytes you put in it. For example, those bytes might be using ISO-8859-1 encoding... or any other, really: the information about the encoding is just not there -- you have to know where the bytes were coming from!

    0 讨论(0)
  • 2020-11-30 06:57

    std::string contains any sequence of bytes, so the encoding is up to you. You must know how it is encoded. However, if you don't know that it is something else, it's probably just ASCII. In which case, it's already UTF-8 compatible.

    0 讨论(0)
提交回复
热议问题