how to back to the first of text file

Posted by Naeim on Stack Overflow See other posts from Stack Overflow or by Naeim
Published on 2010-04-24T16:06:59Z Indexed on 2010/04/24 16:13 UTC
Read the original article Hit count: 170

Filed under:

i have a txt file which have some lines ...and my code is :

    string line;
ifstream myfile("c:\\main.txt");


bool passport = true;



while(passport==true){

    int pos1=0;
cout<<setw(20)<<"PassPort_Number : ";
cin>>add.Id ;
 if (myfile.is_open())
  {
            while(!myfile.eof()){
            getline(myfile,line);
            pos1+=line.find(add.Id);
            cout<<pos1;
            }}

if(pos1<0)
passport=false;
else {
    cout<<"PassPort Number tekrariye :d"<<endl;



}

}

first time everything is ok but at the second time of running it doesn't enter to second while (while(!myfile.eof() ) ... what's wrong with my code?

when it goes to the end of text file it doesn't back to the first of file at the next loop ... how can i back to the first of text file ?

© Stack Overflow or respective owner

Related posts about c++