I have this code which runs fine
#include <iostream>
#include <set>
#include <sstream>
int main()
{
std::set<std::string> a;
a.insert("foo");
a.insert("bar");
a.insert("zoo");
a.insert("should");
a.insert("work");
std::stringstream b;
std::set<std::string>::iterator it;
for (it = a.begin(); it != a.end(); it++)
{
b << " " << *it <<"," <<"\n";
}
std::string aaa = b.str();
std::cout <<aaa;
}
Output in command prompt:
bar, //new line after ","
foo, //new line after ","
should,
work,
zoo,
If I try to write the same string aaa in file I am expecting the same output to get print in the file i.e. every string after "," in new line, rather I am getting output in my file as follows (In single line with \n):
" bar,\n foo,\n should,\n work,\n zoo,\n"
Can anyone help me with this?
More Information on writing the string in file:
Here's how I am writing into file:
boost::property_tree::ptree pt1;
pt1.put( "Output", aaa );
boost::property_tree::write_json( "result.json", pt1 );
This will write JSON file, output of the above code in (Windows - NotePad/NotePad++) is as below:
{
"Output": " bar,\n foo,\n should,\n work,\n zoo,\n"
}