std :: string.c_str()使用什么编码? [英] What encoding does std::string.c_str() use?

查看:427
本文介绍了std :: string.c_str()使用什么编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将C ++ std :: string 转换为UTF-8或 std :: wstring 丢失信息(考虑包含非ASCII字符的字符串)。

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

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


如果std :: string有非ASCII字符,你必须提供一个函数,从你的编码转换为UTF-8 [...]

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

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

推荐答案

std :: string 本身不使用编码 - 它会返回你放入的字节。例如,这些字节可能使用ISO-8859-1编码...或任何其他,真的:关于编码的信息只是不是 - 你必须知道字节来自哪里!

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!

这篇关于std :: string.c_str()使用什么编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆