Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:21:10+00:00 2026-06-15T19:21:10+00:00

I have the following code that adds data to a rapidjson::Document, declared thus: rapidjson::Document

  • 0

I have the following code that adds data to a rapidjson::Document, declared thus:

rapidjson::Document rest;
rest.SetObject();

in a loop.

Value v(value.c_str());
stringstream ss;//create a stringstream
ss << "a" << colnum;
const char* colnumstr = ss.str().c_str();     
cout << "json: colnumstr = \"" << colnumstr << "\", value = \"" << value << "\"" << endl;
rest.AddMember(colnumstr,v,rest.GetAllocator());

When the loop is over I add the json as a string to a map, like so:

StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
rest.Accept(writer);

string reststring = buffer.GetString();
cout << "Pushing " << reststring << " to map" << endl;
parseddata["rest"].push_back(reststring);

Heres the wierd bit:

json: colnumstr = "a1", value = "13745438"
json: colnumstr = "a2", value = "#N/A"
json: colnumstr = "a9", value = "Top 19"
Pushing {"a1":"9999\u0000438","99":"#N/A","31":"Top 19"} to map

Certain values seem to be getting changed. But I have no idea how or why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:21:11+00:00Added an answer on June 15, 2026 at 7:21 pm

    First thing I see is this mistake (maybe not related to your problem) :

    const char* colnumstr = ss.str().c_str();
    

    This is wrong, why :

    ss.str() : Return a copy of the string instance.

    .c_str() : Get the internal data of this string

    But the string instance is destroy the next line, before printing the result, so the colnumstr pointer is pointing to something not valid in memory. Hopefully most of the time the data are still valid… But in some case the data can be overwritten by something else.

    The proper solution is to do

    string colnumstrObj = ss.str();
    const char* colnumstr = colnumstrObj .c_str();
    

    The colnumstrObj will be destroy at the end of the function and not immediately…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code that adds data to unordered lists. The troublesome code
I have following code that does not work due to a being a value
I have the following code that adds a record to my MySQL database via
I have the following code that adds a background worker into a VB.net WPF
I have the following code that adds an observer in the loading of the
I have the following code that adds a file upload option to a div
I have the following code that exports a csv file : //Selecting Item Data
I have following code that I am compiling in a .NET 4.0 project namespace
I have following code that does not work: I never get to goToFoodDetail .
I have following code snippet that i use to compile class at the run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.