cant read whole string in file handling

Jun 2, 2015 at 6:08pm
using this for cin

1
2
3
4
5
6
 ofstream newsuspect("newsuspect.txt", ios::app);
 system("cls");
 cin.ignore();
 cout << "Enter the new suspect's name" << endl;
 getline(cin,name);
newsuspect << name;

& this code to read from file
1
2
3
4
ifstream suspect("newsuspect.txt");
 while (suspect >> name ){
     cout << setw(10)<< name << setw(10) << age <<setw(10)<< cno <<' '<<endl ;
     }

IT doesnt read whole string (including spaces)
Last edited on Jun 2, 2015 at 6:17pm
Jun 2, 2015 at 8:44pm
You can just use while(getline(suspect,name)) as well.
Jun 2, 2015 at 9:18pm
some random number shows up :/
Topic archived. No new replies allowed.