adding numbers to end of file.

May 8, 2013 at 2:00pm
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");
}
May 8, 2013 at 2:03pm
You should check whether the file was opened successfully.
May 8, 2013 at 2:04pm
yes that is checked before operation6 is ran
May 8, 2013 at 2:05pm
file.c_str should be file.c_str().
May 8, 2013 at 2:05pm
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 );
May 8, 2013 at 2:08pm
ah ok, thought you didn't need those when there was more after.

Thanks guys but now its still overwriting the file.
May 8, 2013 at 2:14pm
Maybe try ios_base::app rather than ios_base::ate
May 8, 2013 at 2:16pm
Try to add ios_base::app
May 8, 2013 at 2:17pm
awesome thankyou it works
Topic archived. No new replies allowed.