You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cant modify existing numbers inside a json object #557
terminate called after throwing an instance of 'std::domain_error'
what(): cannot use push_back() with number
I tried simplifying it to
j["num"] = j["num"] + 1;
but that gives me this error at compile time: error: no match for 'operator+' (operand types are 'nlohmann::basic_json<>::value_type {aka nlohmann::basic_json<>}' and 'int')|
In addition to @gregmarr s remarks: += is an overload for json::push_back and can only be called on a JSON array. And indeed the + operator has no overload for json and int.
Activity
gregmarr commentedon Apr 17, 2017
j["num"]is ajsonobject, not anint. You need toget()theintout of it before you can add 1 to it and assign it back again.nlohmann commentedon Apr 19, 2017
In addition to @gregmarr s remarks:
+=is an overload forjson::push_backand can only be called on a JSON array. And indeed the+operator has no overload forjsonandint.To increment
j["num"], you need to callor
nlohmann commentedon Apr 22, 2017
@AMScaglione Does this work for you?
AMScaglione commentedon Apr 23, 2017
nlohmann commentedon Apr 23, 2017
No problem.