Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fstream outfile("")

Status
Not open for further replies.

fayevalentine

Programmer
Jun 2, 2004
38
MX
Hi!
I have a little problem, I am writing to a file with this code:

ofstream outfile("c:\\salida.dat");
outfile<<1<<" "<<2<<" "<<3<<" "<<4<<"\n"<<5<<" "<<6<<" "<<7<<" "<<8;
outfile.close();

but when a write a new data all existing data are erased.
What can I do to append my new data?
Thank you.
 
Hi,

Create your output stream like this :

ofstream outfile("c:\\salida.dat", ofstream::app);

--
Globos
 
Also try:
Code:
ofstream outfile("c:\\salida.dat", ios::app);

If the standard namespace is not globally defined you may have to use:
Code:
ofstream outfile("c:\\salida.dat", std::ios::app);

James P. Cottingham
-----------------------------------------
To determine how long it will take to write and debug a program, take your best estimate, multiply that by two, add one, and convert to the next higher units.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top