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..

>>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.

Thank you!! That solved my problem!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.