【发布时间】:2017-04-09 16:58:50
【问题描述】:
我的 json 需要测试一个包含 utf16 宽字符的字符串,但我收到以下错误消息:
\..\test\TestClass.cpp(617): error C2440: 'initializing' : cannot convert from 'const char [566]' to 'std::basic_string<_Elem,_Traits,_Ax>'
with
2> [
2> _Elem=wchar_t,
2> _Traits=std::char_traits<wchar_t>,
2> _Ax=std::allocator<wchar_t>
2> ]
2> No constructor could take the source type, or constructor overload resolution was ambiguous
这是我的 json:
static std::wstring& BAD_JSON5_missingComma_multipleNewlines_Utf16MixedDosAndUnixLineEndings()
{
static std::wstring j =
"{\n" <=VS squigly says error on this line
"\"header\":{\n"
"\"version\":{\"major\":1,\"minor\":0,\"build\":0}\n"
"},\n"
"\"body\":{\n"
"\"string\":{\"type\":\"OurWideStringClass\",\"value\":\"foo\"},\n\n\n\n"
"\"int\":[\n"
"{\"type\":\"string\",\"value\":\"\\u9CE5\"},\n"
"{\"type\":\"Int\",\"value\":5678}\n"
"],\n"
"\"double\":{\"type\":\"Double\",\"value\":12.34},\n"
"\"path1\":[\n"
"{\n"
"\"string\":{\"type\":\"OurWideStringClass\",\"value\":\"bar\"},\r\n"
"\"int\":[\n"
"{\"type\":\"Int\"\"value\":7},\n"
"{\"type\":\"Int\",\"value\":11}\n"
"]\n"
"},\n"
"{\n"
"\"string\":{\"type\":\"OurWideStringClass\",\"value\":\"top\"},\n"
"\"int\":[\n"
"{\"type\":\"Int\",\"value\":13},\r\n"
"{\"type\":\"Int\",\"value\":41}\n"
"]\n"
"}\n"
"],\n"
"\"path2\":{\n"
"\"int\":{\"type\":\"Int\",\"value\":-1234},\n"
"\"double\":{\"type\":\"Double\",\"value\":-1.234}\r\n"
"}\n"
"}\n"
"}\n"; <=double clicking build error goes to this line
return j;
}
这就是它的使用方式
OurWideStringClass slxStJson5 = BAD_JSON5_missingComma_multipleNewlines_Utf16MixedDosAndUnixLineEndings();
std::wistringstream ssJsonMissingCommaUtf16Newlines(slxStJson5);
我以为我的 wchar_t 在我的 json 中被 std::wstring 覆盖。有什么想法有什么问题吗?您可以在 \u9ce5 中看到我的 utf16 字符。这是本次测试的关键。
我查看了这个c2440,但看不到他们在关于 UDT 的决议中指的是什么。
我在看前面的这个which puts an L ,但是用转义的c字符串,我不知道把L放在哪里。
【问题讨论】: