2

I am trying to use rapidjson to output itself to a string to save to a database, using the following code :

StringBuffer buffer;
Writer<FileStream> writer(buffer);
rest.Accept(writer);
string reststring = buffer.GetString();

where rest is a rapidjson::Document.

However I get the following error :

no matching function for call to ‘rapidjson::Writer<rapidjson::FileStream>::Writer (rapidjson::StringBuffer&)’.

which is strange because the author of rapidjson recommended this method in an answer to a previous SO question.

placeybordeaux
  • 2,138
  • 1
  • 20
  • 42
Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59

3 Answers3

6

I must have been tired at 9 last night when I wrote this piece of code.

Changing

Writer<FileStream> writer(buffer);

to

Writer<StringBuffer> writer(buffer);

solves the problem.

Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59
4

Try to use rapidjson::StringBuffer and rapidjson::Writer for get string output.

rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
rest.Accept(writer);
std::string str = buffer.GetString();

Here you can get value in both string as well as std::string. Above I used std::string for get value. This works...

Arvind Kanjariya
  • 2,089
  • 1
  • 18
  • 23
0

As your compiler suggest, you have to modify your code in:

 StringBuffer buffer;
 Writer<FileStream> writer(&buffer);

Or:

 StringBuffer* buffer;
 Writer<FileStream> writer(buffer);
Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146