File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -85,16 +85,19 @@ Json::StreamWriter::Builder builder;
85
85
builder.withIndentation(" "); // or whatever you like
86
86
87
87
// Then build a StreamWriter.
88
- // (Of course, you can write to std::ostringstream if you prefer.)
89
88
std::shared_ptr<Json::StreamWriter> writer(
90
- builder.newStreamWriter( &std::cout );
89
+ builder.newStreamWriter( &std::cout ) ) ;
91
90
92
91
// Make a new JSON document for the configuration. Preserve original comments.
93
92
writer->write( root );
94
93
95
94
// If you like the defaults, you can insert directly into a stream.
96
95
std::cout << root;
97
96
97
+ // Of course, you can write to `std::ostringstream` if you prefer. Or
98
+ // use `writeString()` for convenience.
99
+ std::string document = Json::writeString( root, builder );
100
+
98
101
// You can also read from a stream. This will put the contents of any JSON
99
102
// stream at a particular sub-value, if you'd like.
100
103
std::cin >> root["subtree"];
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ class StreamWriterBuilder;
27
27
/* *
28
28
29
29
Usage:
30
-
30
+ \code
31
31
using namespace Json;
32
32
Value value;
33
33
StreamWriter::Builder builder;
@@ -36,16 +36,18 @@ class StreamWriterBuilder;
36
36
builder.newStreamWriter(&std::cout));
37
37
writer->write(value);
38
38
std::cout.flush();
39
+ \endcode
39
40
*/
40
41
class JSON_API StreamWriter {
41
42
protected:
42
43
std::ostream& sout_; // not owned; will not delete
43
44
public:
44
- // / `All`: Keep all comments.
45
- // / `None`: Drop all comments.
46
- // / Use `Most` to recover the odd behavior of previous versions.
47
- // / Only `All` is currently implemented.
48
- enum class CommentStyle {None, Most, All};
45
+ // / Decide whether to write comments.
46
+ enum class CommentStyle {
47
+ None, // /< Drop all comments.
48
+ Most, // /< Recover odd behavior of previous versions (not implemented yet).
49
+ All // /< Keep all comments.
50
+ };
49
51
50
52
// / Keep a reference, but do not take ownership of `sout`.
51
53
StreamWriter (std::ostream* sout);
You can’t perform that action at this time.
0 commit comments