mirror of
https://github.com/nlohmann/json.git
synced 2026-02-28 06:16:24 +00:00
🐛 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.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <json.hpp>
|
||||
#include <iomanip> // 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';
|
||||
|
||||
Reference in New Issue
Block a user