Thread: How do I clear ifstream!?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    10

    How do I clear ifstream!?

    I am trying to write a simple spell checking program but no matter what I do it will only read through the word list once and all other times it just thinks it is the end of the file and does a check for the first word I put in...

    Here is the code:
    Code:
    while (repeat==true) {
            word_list.clear();
            word_list.seekg(0, ios::beg);
            cout << "\n\nType word here (lowercase): ";
            cin  >> input;
            system("clear");
                while (!word_list.eof()) {
                    word_list >> read;
                    cout << "\nTrying: " << read;
                    if (read==input) {
                        system("clear");
                        cout << " is a word!\n\n";
                        repeat=true;
                        //word_list.close();
                        word_list.clear();
                        word_list.seekg(0, ios::beg);
                        break;
                    }
                    else{
                        check0=1;
                    }
                }
                if (read!=input) {
                    system("clear");
                    //word_list.close();
                    word_list.clear();
                    word_list.seekg(0, ios::beg);
                    cout << "\n\n" << input << " is not a word!\n\n";
                }
                
            }
    EDIT: Resolved: removing word_list.close() fixed the issue
    I attached the full cpp file for reference...
    Attached Files Attached Files
    Last edited by jacobfreemaninc; 04-30-2011 at 11:26 PM. Reason: Resolved: removing word_list.close() fixed the issue

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ifstream
    By Know_Your_Role in forum C++ Programming
    Replies: 2
    Last Post: 12-10-2009, 07:05 AM
  2. ifstream
    By Wraithan in forum Tech Board
    Replies: 3
    Last Post: 09-24-2006, 01:26 AM
  3. need help with ifstream
    By stillwell in forum C++ Programming
    Replies: 6
    Last Post: 06-20-2005, 09:23 AM
  4. ifstream
    By krappykoder in forum C++ Programming
    Replies: 7
    Last Post: 12-20-2002, 11:38 AM
  5. ifstream
    By cppdude in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2002, 04:06 PM

Tags for this Thread