From 951d0920fc0a42476846bc2e6eb3ed7428dc81c1 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 14 Apr 2017 17:36:45 +0200 Subject: [PATCH] :bug: fixed README example The example with the size() operator is bad: using operator[] already changes the size of the object. The fix makes it clearer. --- doc/examples/README.cpp | 4 +++- doc/examples/README.output | 27 --------------------------- 2 files changed, 3 insertions(+), 28 deletions(-) delete mode 100644 doc/examples/README.output diff --git a/doc/examples/README.cpp b/doc/examples/README.cpp index b928e116..d8cd4d67 100644 --- a/doc/examples/README.cpp +++ b/doc/examples/README.cpp @@ -1,4 +1,5 @@ #include +#include // for std::setw using json = nlohmann::json; @@ -29,7 +30,8 @@ int main() j["new"]["key"]["value"] = {"another", "list"}; // count elements - j["size"] = j.size(); + auto s = j.size(); + j["size"] = s; // pretty print with indent of 4 spaces std::cout << std::setw(4) << j << '\n'; diff --git a/doc/examples/README.output b/doc/examples/README.output deleted file mode 100644 index 3226f729..00000000 --- a/doc/examples/README.output +++ /dev/null @@ -1,27 +0,0 @@ -{ - "answer": { - "everything": 42 - }, - "happy": true, - "list": [ - 1, - 0, - 2 - ], - "name": "Niels", - "new": { - "key": { - "value": [ - "another", - "list" - ] - } - }, - "nothing": null, - "object": { - "currency": "USD", - "value": 42.99 - }, - "pi": 3.141, - "size": 9 -}