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