久しぶりにC++ネタ。JSONを生成するプログラムをC++で書こうなんて人がそもそもいない気もするが、boost::property_tree::write_json()
を使うと簡単にJSON出力ができる。
#include <iostream>
#include <sstream>
#include <boost/property_tree/json_parser.hpp>
using namespace std;
int main(int argc, char *argv[])
{
if(argc < 2)
{
cerr << "Usage: " << argv[0] << " message" << endl;
return 1;
}
boost::property_tree::ptree pt;
pt.put("message", argv[1]);
boost::property_tree::write_json(cout, pt, false);
return 0;
}
Continue reading »