gpt4 book ai didi

c++ - VisualStudio 2013 中的 rapidJSON 和 UNICODE

转载 作者:行者123 更新时间:2023-11-28 00:22:53 24 4
gpt4 key购买 nike

我遇到了一个我不确定如何解决的问题。这是我的代码。

#include "rapidjson/write.h"
#include "rapidjson/stringbuffer.h"

...

void WriteResultToJSON()
{
CHAR a[] = "a";
TCHAR b[] = _T("b");
WCHAR c[] = L"c";

StringBuffer s;
Writer<StringBuffer> writer(s);
writer.StartObject();
writer.String("A:");
writer.String(a);
writer.String("B");
writer.String(b);
writer.String("C");
writer.String(c);
write.EndObject();
printf(s.GetString());
}

当项目字符集值为“Use Unicode Character Set”时,我无法编译。仅当设置为“使用多字节字符集”时。

错误说:

no instance of overloaded function "rapidjson::Writter<OutputStream, SourceEncoding, Target Encoding, StackAllocator>::String [with OutputStream=rapidjson::StringBuffer, SourceEncoding=rapidjson::UTF8<char>,TargetEncoding=rapidjson::UTF8<char>, StackAllocator=rapidjson::CtrAllocator]" matches the argument list
argument types are (TCHAR [2])
object type is: rapidjson::Writter<rapidjson::StringBuffer, rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator>

我有一种不好的感觉,rapidjson 只支持 utf8,它不能与我当前的项目一起使用,它是 utf16,或者当字符集设置为 unicode 时有没有办法使用它?

谢谢

最佳答案

如果您查看 Writer 类的各种字符串方法,它们都期望将 const SourceEncoding::Ch* 作为输入。默认情况下,SourceEncodingrapidjson::UTF8Chchar。要接受 wchar_t* 输入,您必须指定 rapidjson::UTF16(或 rapidjson::UTF16LE)作为 SourceEncoding,例如:

void WriteResultToJSON()
{
CHAR a[] = "a";
TCHAR b[] = TEXT("b");
WCHAR c[] = L"c";

StringBuffer s;
Writer< StringBuffer > writerUTF8(s); // UTF-8 input
Writer< StringBuffer, UTF16<> > writerUTF16(s); // UTF-16 input

writerUTF8.StartObject();
writerUTF8.String("A:");
writerUTF8.String(a);
writerUTF8.String("B");

#ifdef UNICODE
writerUTF16.String(b);
#else
writerUTF8.String(b);
#endif

writerUTF8.String("C");
writerUTF16.String(c);

writerUTF8.EndObject();
printf(s.GetString());
}

关于c++ - VisualStudio 2013 中的 rapidJSON 和 UNICODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26562830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com