Thread: reread a text file

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    23

    Angry reread a text file

    DEar All.

    I am trying to read same file two times by calling a function as the following.
    Code:
    ifstream fmonju;
      fmonju.open(monju.c_str());
      if(!fmonju.is_open())
      {
        cout<< fmonju<< " can not be opened!!!! \n";
        exit(1);
      }
                           
      ofstream fmonju1;
      fmonju1.open(monju1.c_str());
    
      int cnt=6;
      okuyaz(fmonju,fmonju1,cnt); 
      fmonju.seekg(0,ios::beg);
      cnt=7;
      okuyaz(fmonju,fmonju1,cnt);
    In the okuyaz() function I am using
    Code:
    while(getline(fmonju,line))
      {
         //
      }
    when first time I call the function for cnt=6, it reads fmonju file. However in the second call for cnt=7, it doesn't read. This while loop doesn't work.

    I will appreciate any help.
    thank you!

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > fmonju.seekg(0,ios::beg);
    Try adding a clear() to clear the stream flags:
    Code:
      fmonju.clear();
      fmonju.seekg(0,ios::beg);

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    23
    thank you so much! now it works

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. checking values in a text file
    By darfader in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 02:13 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM