2016-09-22 6 views
0

다음 코드가 있지만 컴파일 할 수 없습니다. 나는 이유를 생각할 수 없다.문자열이있는 RapidJson kArrayType

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

수행

messageArr.PushBack( rapidjson::Value{}.SetString(test.c_str(), test.length(), allocator), allocator ); 
- RapidJosn이 문자열 값의 다른 종류가 있습니다 : 할당 (필요합니다 단순한'const char *'래퍼 (범위를 벗어나면 불어날 것임) 및/또는'짧은 문자열'* 15 ch ars 이하 또는 그와 비슷한 것). 할당자를 원했기 때문에, 당신은 Copy by 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

유창함 스타일 :

이 이 에게
+1

나는 시도했지만 행운이 없다, 다음과 같은 오류가 발생했다. /usr/include/rapidjson/document.h:1342:29 : 오류 : 'rapidjson :: GenericValue > :: GenericValue (std :: __ cxx11 :: basic_string &) ' GenericValue v (값); ^ – nilan

+0

이것을 컴파일 해 보셨습니까? 내 rapidjson을 푸시 백하려고 시도 할 때 동일한 오류가 발생합니다. :: Value & copyFrom에 대해 이야기 할 때 Rapidjson 자습서에있는 것처럼 말입니다. – Michele