adding numbers to end of file.

Im trying to write a number to the end of a file
but it does not work.

file is the name of the file being sent to this function "test"

1
2
3
4
5
6
7
8
9
 void operation6(string file)
{
	ofstream outfile;
	file += ".txt";
	outfile.open(file.c_str, ios_base::ate );
	outfile << 11;
	outfile.close();
	system ("pause");
}
You should check whether the file was opened successfully.
yes that is checked before operation6 is ran
file.c_str should be file.c_str().
I do not see where this check is. I see an invalid statement instead

outfile.open(file.c_str, ios_base::ate );

Shall be

outfile.open(file.c_str(), ios_base::ate );
ah ok, thought you didn't need those when there was more after.

Thanks guys but now its still overwriting the file.
Maybe try ios_base::app rather than ios_base::ate
Try to add ios_base::app
awesome thankyou it works
Topic archived. No new replies allowed.