mtb mtb - 1 year ago 92
C++ Question

conversion from 'size_t' to 'rapidjson::SizeType'

I have this c++ example code:

void test()
rapidjson::Document doc;

const std::string source = "The quick brown fox jumps over the lazy dog";
rapidjson::Value source_val;
source_val.SetString( source.c_str(), source.length(), doc.GetAllocator() );

And at compile time, on x64 platform, I get this warning:

warning C4267: 'argument': conversion from
, possible loss of data

How can I correctly convert from a string's length (
) to rapidjson SizeType?

Answer Source

Per the documentation:

RapidJSON uses 32-bit array/string indices even on 64-bit platforms, instead of using size_t. Users may override the SizeType by defining RAPIDJSON_NO_SIZETYPEDEFINE.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download