fstream getline() Unhandled exception

自古美人都是妖i 提交于 2019-12-11 09:08:23

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/13272562/fstream-getline-unhandled-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!