我正在尝试将 C++ std::string
转换为 UTF-8 或 std::wstring
而不会丢失信息(考虑包含非 ASCII 字符的字符串)。
根据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 [...]
std::string.c_str()
使用什么编码?如何以跨平台方式将其转换为 UTF-8 或 std::wstring
?
最佳答案
std::string
本身不使用编码——它将返回您放入其中的字节。例如,这些字节可能正在使用 ISO-8859-1 编码...或任何其他编码,真的:关于编码的信息不存在——您必须知道这些字节来自哪里!
关于c++ - std::string.c_str() 使用什么编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1010783/