Thread: File Input error...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    83

    File Input error...

    I'm trying to read a file that uses 0xd7 and 0x0d as delimiters and the following code keeps failing:

    Code:
    bool readFile(string FileName, vector<string>* FileOutput) {    
        string      currLine;
        ifstream    theFile(FileName.c_str());
        
        if(theFile.is_open()) {
            while(theFile.good()) {
                getline(theFile,currLine);
                FileOutput->push_back(currLine);
            }
            theFile.close();
            return true;
        }
        return false;
    }

    Can anyone suggest a way around this? I'm really stuck.

    I tried fixing the text file with a python script, but there to got an error: "UnicodeDecodeError: 'ascii' codec can't decode byte 0xd7 in position 9: ordinal not in range(128)"

    Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Fails how?

    Tokenises on 0x0D, but doesn't on 0xD7 ?
    Well you could do what you're doing at the moment, then add code following your getline to split all 0xD7 delimiters.

    Doesn't read 0xD7 at all, for much the same reason as python?

    Reads the last line twice, because of the broken while loop?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input File Error
    By MechAggie in forum C++ Programming
    Replies: 11
    Last Post: 06-28-2008, 06:49 PM
  2. BUS error when reading input from file
    By gkoenig in forum C Programming
    Replies: 5
    Last Post: 05-05-2008, 03:48 PM
  3. Bus error when reading input from file
    By gkoenig in forum C Programming
    Replies: 6
    Last Post: 03-29-2008, 03:05 PM
  4. error reading input from file
    By drharv in forum C Programming
    Replies: 3
    Last Post: 06-12-2002, 05:43 PM
  5. input file error message
    By sven72 in forum C++ Programming
    Replies: 1
    Last Post: 05-21-2002, 01:04 AM