2016-09-22 10 views
0

次のコードがありますが、コンパイルできません。 私は理由を考えることができません、拾い読みしてください。RapidJson kArrayType with String

rapidjson::Document jsonDoc; 
jsonDoc.SetObject(); 
rapidjson::Document::AllocatorType& allocator = jsonDoc.GetAllocator(); 

rapidjson::Value messageArr(rapidjson::kArrayType); 

std::string test = std::string("TEST"); 
messageArr.PushBack(test.c_str(), allocator); 

以下のエラーが表示されます。

error: no matching function for call to ‘rapidjson::GenericValue >::PushBack(const char*, rapidjson::GenericDocument >::AllocatorType&)’
messageArr.PushBack(test.c_str(), allocator);

+0

が完了 - RapidJosnは、文字列値の異なる種類があります。割り当てられた(必要があります。単純な 'const char *'ラッパー(範囲外になると壊れる)や短い文字列* 15 ch ars以下またはそれ以上のもの)。アロケータが必要だったので、コピーしたStrValueが必要だと仮定しました。 –

答えて

1

[編集] - ソリューション:

std::string test = std::string("TEST"); 
    rapidjson::Value strVal; 
    strVal.SetString(test.c_str(), test.length(), allocator); 
    messageArr.PushBack(strVal, allocator); 

流暢スタイルRapidJson tutorial - Create String

を参照してください:

messageArr.PushBack(
     rapidjson::Value{}.SetString(test.c_str(), test.length(), allocator), 
     allocator 
); 
+1

私は試しましたが、運がなかったので、次のエラーが表示されます。 /usr/include/rapidjson/document.h:1342:29:エラー: 'rapidjson :: GenericValue > :: GenericValue(std :: __ cxx11 :: basic_string &) ' GenericValue v(値); ^ – nilan

+0

あなたはこれをコンパイルすることができましたか?私はrapidjson :: Value&をプッシュバックしようとしたときに同じエラーが発生します。これは、copyFromについて話をするときにrapidjsonのチュートリアルにあるようです。 – Michele

関連する問題