Aug 21, 2012 at 11:16pm UTC
figured adding break ;
before case 3:
solved my problem. thank you so much.
Last edited on Aug 21, 2012 at 11:16pm UTC
Aug 22, 2012 at 12:57am UTC
okay i have a new problem here. If a user add option 3 a number of times it just add to outFile.
Aug 22, 2012 at 10:22am UTC
this problem won't end anywhere i guess. As soon as i choose option 3,option 2 and option 3 i am back to same old situation. What am i doing wrong here??
Aug 22, 2012 at 10:51am UTC
It would be good to make functions for each case that makes the situation more clear.
I don't know what the old situation is, but I'd suggest in case 3: to open the file -> write -> close the file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
case 3:
{ // These braces are necessary otherwise switch won't allow local variabel
ofstream outFile("out.txt" );
if (outFile)
{
for (int i=0;i<database.size();i++)
{
database[i]->save(outFile);
cout<<endl;
}
outFile.close();
}
}
break ;
Remove line 13
[EDIT]
To make sure that the data is always newly written add flags when open the file:
ofstream outFile("out.txt" , ofstream::out | ofstream::trunc);
See:
http://cplusplus.com/reference/iostream/ofstream/ofstream/
[/EDIT]
Last edited on Aug 22, 2012 at 11:31am UTC
Aug 22, 2012 at 11:27am UTC
coder777 you are one amazing person. You just helped me a lot. You got a blog or something i can follow?? Thank u so much!!
i will see if there are other problems before marking it as solved!!
Aug 22, 2012 at 4:48pm UTC
well, you were on the right track and willing to solve the problem. so not that amazing...