0
void addname(string name)
{

  ofstream myfile(CONTACTS,ios::app );
  myfile.open(CONTACTS);
  if (myfile.is_open());
  {
  myfile<<i++<<name<<endl;
  myfile.close();
  }
  
  
  
}

Initially the codes just kept on overwriting the existing file, but after that i was told to put ios::app. However, it is still now working....now even worse...ofstream is not even writing the file...hellp..

Edited by Bigbrain99: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Bigbrain99
0

>>is this the right way to do append ofstream?
No. Delete line 5 because line 4 opens the file in append mode. Its not writing to the file because of line 5.

0

Thank you!! That solved my problem!

Edited by Bigbrain99: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.