removing old data from json file #3506
Unanswered
lord-ilghar
asked this question in
Q&A
Replies: 2 comments
-
and sorry its my first time asking in github |
Beta Was this translation helpful? Give feedback.
0 replies
-
Just use the correct open mode for the stream (see https://en.cppreference.com/w/cpp/io/basic_ofstream/basic_ofstream). Specifically, you want to use (at least) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hey,
i have system that records the highest delta time in my little game engine and saves it in to json file for future.
but when i try to save the data to my json file it appends it, but i want to remove the old stuff it that file
here is my code:
std::fstream performaceRecord;
performaceRecord.open("perf.json");
if (performaceRecord.is_open()) {
std::cout << "OPEND" << std::endl;
}
eng::json performancejson;
performaceRecord >> performancejson;
if(performancejson["delta_time"] < DeltaTime){
json newjson = {
{"delta_time" , DeltaTime},
{"fps" ,fps},
{"objects_amount" , objectsAmount},
{"deltaTime_changes" , DeltaTimeChanges}
};
performaceRecord << std::setw(4) << newjson << std::endl;
}
and i get this in json file :
{
"delta_time": 0,
"fps": 0,
"objects_amount": 0,
"deltaTime_changes": 1
}{
"deltaTime_changes": [
1.0,
1.0
],
"delta_time": 0,
"fps": 10,
"objects_amount": 1
}
and i am using visual studio 2019
Beta Was this translation helpful? Give feedback.
All reactions