내가 명령 프롬프트에서 좋은새로운 라인은 파일 출력에 n을 함께 볼 수있다
#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;
}
출력 실행이 코드가 있습니다
bar, //new line after ","
foo, //new line after ","
should,
work,
zoo,
하는 경우를 나는 동일한 문자열을 파일에 쓰려고 노력한다. 같은 출력이 파일에서 인쇄를하기를 기대하고있다. ","새 줄에 다음과 같이 출력한다. (한 줄에 \ n) :
" bar,\n foo,\n should,\n work,\n zoo,\n"
아무도 도와 줄 수 있습니까?
boost::property_tree::ptree pt1;
pt1.put("Output", aaa);
boost::property_tree::write_json("result.json", pt1);
이 JSON 파일, 위의 코드의 출력을 작성합니다 : 다음
내가 파일에 쓰고 어떻게 : 파일에 문자열을 작성하는 방법에
추가 정보 (Windows - NotePad/NotePad ++)는 다음과 같습니다 :
{
"Output": " bar,\n foo,\n should,\n work,\n zoo,\n"
}
Windows 또는 Linux를 사용하고 있습니까? 줄 끝의 차이와 같은 소리가 문제입니다. – NathanOliver
어떻게 파일을 열어보고 있습니까? 편집기에서 여는 경우 따옴표 나 '\ n'을 볼 수 없습니다. –
문제가있는 파일을 파일에 쓰는 코드를 게시하십시오. –