fstream getline() Unhandled exception

1

am trying to read a file so am doing:-

void Load(const char * Name){
    fs.open(Name, std::ifstream::in);
        char temp[256];

    if(fs.is_open()){

        while (!fs.eof())
        {
            fs.getline(temp , 256);
            Lines.push_back(new std::string(temp));
        }
}
}

but it breaks on the getline ->

Unhandled exception at 0x7730B4D9 (ntdll.dll) in GameCore.exe: 0xC0000005: Access violation writing location 0x00000014.

where it's check

else
            /*
             * Not part of _iob[]. Therefore, *pf is a _FILEX and the
             * lock field of the struct is an initialized critical
             * section.
             */
            EnterCriticalSection( &(((_FILEX *)pf)->lock) );

in the _file.c file , what's wrong here?

c++
visual-c++
getline
asked on Stack Overflow Nov 7, 2012 by Abanoub

1 Answer

2

When you encounter these sorts of issues you may want to double check your project configuration. For example, in MSVC check your Project Properties > Configuration Properties > C/C++ > Code Generation > Runtime Library. Make sure it consistent for all dependencies and that it is set to a Debug/Release variant depending on the current build.

answered on Stack Overflow Dec 31, 2012 by user1556435

User contributions licensed under CC BY-SA 3.0