
December 9th, 2004, 11:07 AM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Here it is. Haven't figured it out yet. I have gotten it to read the first line from the file with getline but it doesn't do the trick(not in this code).
Quote: #include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int main ()
{
int option;
while (exit) {
cout<<"\nCurrently available options:\n\n 1 shows your todo list \n 2 add note to your list \n 3 clear your list \n 4 quit \n\n";
cout <<"What is your choice: "; cin >> option;
cin.ignore();
if ( option == 1 )
{
char show[256];
ifstream todofile ("todo.txt");
if (! todofile.is_open())
{
cout << "Error opening file";
}
while (! todofile.eof() )
{
todofile.getline (show,100);
cout << "\n\n\n" << show << endl;
}
}
if ( option == 2 )
{
{
char add[256];
ofstream todofile ("todo.txt",ios::app);
if (todofile.is_open())
{
cout << "Insert note: ";
cin.getline(add,256);
todofile << add <<"\n" ;
}
}
}
if ( option == 3 )
{
cout << "\n Your TODO list have been cleared \n \n";
ofstream todofile ( "todo.txt",ios::trunc );
}
if ( option == 4 )
{
cout <<"\n Bye Bye!! \n\n";
return 0;
}
}
return 0;
} | As you can see it truncates whole file. It's not very good option.
|