C++ – What encoding does std::string.c_str() use


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).

According to http://forums.sun.com/thread.jspa?threadID=486770&forumID=31:

If the std::string has non-ASCII characters, you must provide a function that converts from your encoding to UTF-8 […]

What encoding does std::string.c_str() use? How can I convert it to UTF-8 or std::wstring in a cross-platform fashion?

Best Solution

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!