How do I write into a JSON file from C++? I am using nlohmann's json.hpp and included it into my c++. I want to store some information like "name" "age" "tel" and "mail" in a json file that i can write into from my c++ programm.
I have know how to write into a JSON using data["Infos"][0]["name"] = "Joe"; JSON before that:
{
"Infos": [
{
"name": "Lukas",
"age": "16",
"tel": "1233321",
"mail": "[email protected]"
}
]
}
After running the code, the "name" gets changed to "Joe", but i have no clue how to add another guy to that json that it looks like that:
{
"Infos": [
{
"name": "Lukas",
"age": "16",
"tel": "1233321",
"mail": "[email protected]"
},
{
"name": "New",
"age": "50",
"tel": "123456789",
"mail: "[email protected]"
}
]
}
I have code in my C++ that asks the user for the new guys name, age, tel and mail but i dont know how to add that information to my json file. Sorry for bad english or formating some stuff in ways that aren't easy understandable but i tried my best :D
If anyone has an idea of how this could be possible, or have questions yourself, I appreciate every answer/question to this post!
This is my first question so i didnt know that you have to write the things you tried seperately sorry, i listed everything i tried so far and what i was expecting in the details part of my question