【发布时间】:2015-10-09 09:40:56
【问题描述】:
我有以下代码:
#include <iostream>
#include <string>
#include <locale>
#include <codecvt>
using namespace std;
int main()
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
const char val[] = "+3°C";
wstring text = converter.from_bytes(val);
return 0;
}
问题是converter.from_bytes方法抛出了异常。为什么?我应该如何解析给定的字符串?
异常类型为std::range_error,带有消息
错误的转换
问题与字符“°”有关,因为如果我删除此字符,转换工作正常。
【问题讨论】:
-
什么异常?你为什么不告诉我们? :(
-
@LightnessRacesinOrbit 它对我不起作用,请查看我的编辑。我正在使用 Visual Studio 2013。
-
好多了;现在只需将您的编译环境的详细信息添加到问题中即可。 :)
-
源文件中有非 ASCII 字符。这是非标准的。您受编译器供应商的摆布。如果您使用的是 MSVC,您最好使用what MS is telling you to。
标签: c++ c++11 exception wstring