Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 764531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:44:34+00:00 2026-05-14T16:44:34+00:00

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

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:44:35+00:00Added an answer on May 14, 2026 at 4:44 pm

    Call:

    myfile.seekg(0, ios::beg);
    

    to set the file read pointer back to the beginning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a txt file which actually is a html source of some webpage.
I have a java.hprof.txt file (automatically generated after an OutOfMemoryError) which I would like
I have a file 'records.txt' which contains over 200,000 records. Each record is on
I have a generated txt file. This file has certain lines that are superfluous,
I have to read a txt file with lines formated like this: 1: (G,
I have this txt file which is ls -R of etc directory in a
I have a text file and I want to remove some lines that contain
I have a .txt file that I need to include into a page, that
I have quite a large list of words in a txt file and I'm
I have a file temp.txt, that I want to sort with the sort command

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.