Writing and reading a CSV file

rr
Last edited on
How do i make it so when the program is restarted and new data is inputted the data appends to the file instead of overwriting it?

You'll need to use the optional second parameter to your ofstream constructor to alter the default behavior of truncating the file when opening. Something like: std::ofstream("YourFile", std::ios::app);

1
2
3
4
workoutlogger::workoutlogger()
{
	...
		workoutlogger();

Watch out about recursively calling this constructor, you would be better off with a loop.

And remember in C++ not everything must be in a class.

My other question is how can i repeat the function in the same run of the program?
once i press ctrl z to end the inputs the file just stops

A loop, possibly in main()? And again remember not everything must be inside a class.


Topic archived. No new replies allowed.