C++ Fstream\u Fgetc访问冲突

C++ Fstream\u Fgetc访问冲突,c++,visual-studio-2010,fstream,getline,fgetc,C++,Visual Studio 2010,Fstream,Getline,Fgetc,我想用fstream从文件中读取行(我以前使用过,没有错误),但现在若调用getline,我会得到访问冲突异常。我通过代码从fstream跟踪异常到函数_Fgetc。那个“if”行抛出异常,但我不知道为什么 我想,文件指针可能是空的,但是我能用它做什么呢?或者,我的功能是错误的吗?我想念Visual Studio 2010中的一些设置 我正在使用: #include <vector> #include <istream> #include <fstream>

我想用fstream从文件中读取行(我以前使用过,没有错误),但现在若调用getline,我会得到访问冲突异常。我通过代码从fstream跟踪异常到函数_Fgetc。那个“if”行抛出异常,但我不知道为什么

我想,文件指针可能是空的,但是我能用它做什么呢?或者,我的功能是错误的吗?我想念Visual Studio 2010中的一些设置

我正在使用:

#include <vector>
#include <istream>
#include <fstream>
#include <string>
#包括
#包括
#包括
#包括
我的职能:

bool ImageOp::parseMap(LPTSTR filename){
if(filename == NULL) return false;

fstream ifs;
ifs.open ( "me_l1.dm" , ios::in );

if(!ifs.is_open())
    return false;

vector<vector<int>> parsedMap;
string line;

while(getline( ifs, line)){
    parsedMap.push_back(splitValues(line));
}

ifs.close();
return true;
}
bool ImageOp::parseMap(LPTSTR文件名){
如果(filename==NULL)返回false;
fstream-ifs;
ifs.open(“me_l1.dm”,ios::in);
如果(!ifs.is_open())
返回false;
向量解析图;
弦线;
while(getline(ifs,line)){
parsedMap.push_back(splitValues(line));
}
ifs.close();
返回true;
}
_来自fstream的导致异常的Fgetc:

template<> inline bool _Fgetc(char& _Byte, _Filet *_File)
{   // get a char element from a C stream
int _Meta;
if ((_Meta = fgetc(_File)) == EOF)
    return (false);
else
    {   // got one, convert to char
    _Byte = (char)_Meta;
    return (true);
    }
}
模板内联bool\u Fgetc(字符和字节,\u文件*\u文件)
{//从C流中获取char元素
国际元;
如果((_Meta=fgetc(_File))==EOF)
返回(假);
其他的
{//找到一个,转换成字符
_字节=(字符)\元;
返回(真);
}
}
fstream中还有另外3个重载函数_Fgetc,其中一些带有fread、fgetwc,但我如何控制将使用哪个函数呢

编辑:从我的堆栈中提取:

>ntdll.dll!77178dc9()   
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] 
ntdll.dll!77178cd8()    
msvcrt.dll!752eaad6()   
>DialogBasedApp.exe!std::_Fgetc<char>(char & _Byte, _iobuf * _File)  Line 37 + 0x9 bytes    C++
DialogBasedApp.exe!std::basic_filebuf<char,std::char_traits<char> >::uflow()  Line 435 + 0x10 bytes C++
DialogBasedApp.exe!std::basic_filebuf<char,std::char_traits<char> >::underflow()  Line 413 + 0xf bytes  C++
DialogBasedApp.exe!std::basic_streambuf<char,std::char_traits<char> >::sgetc()  Line 153 + 0x50 bytes   C++
DialogBasedApp.exe!std::getline<char,std::char_traits<char>,std::allocator<char> >(std::basic_istream<char,std::char_traits<char> > && _Istr, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Str, const char _Delim)  Line 412 + 0x23 bytes    C++
DialogBasedApp.exe!std::getline<char,std::char_traits<char>,std::allocator<char> >(std::basic_istream<char,std::char_traits<char> > & _Istr, std::basic_string<char,std::char_traits<char>,std::allocator<char> > & _Str)  Line 483 + 0x2e bytes    C++
DialogBasedApp.exe!ImageOp::parseMap(char * filename)  Line 167 + 0x13 bytes    C++
>ntdll.dll!77178dc9()
[下面的帧可能不正确和/或丢失,没有为ntdll.dll加载符号]
ntdll.dll!77178cd8()
msvcrt.dll!752eaad6()
>DialogBasedApp.exe!STD::FFGEC(char & yByg,yIOBF**文件)行37 +0x9字节C++
DialogBasedApp.exe!STD::Basic文件FieBuf::uFuffor()行435 +0x10字节C++
DialogBasedApp.exe!STD::Basic文件FieBuf::UnFund()行413 +0xf字节C++
DialogBasedApp.exe!STD:StudioBuff::SGET()行153 +0x50字节C++
DialogBasedApp.exe!STD::GETLIN(STD:和C++,STD::Basic字符串SysSTR,const char iDELM)行412 +0x23字节C++
DialogBasedApp.exe!STD::GETLIN(STD:Basic SistReAMi&IistRI,STD::Basic SythSox&Syr)行483 +0x2e字节C++
DialogBasedApp.exe!IMACOP::PARSEMAP(CHAR*文件名)行167 +0x13字节C++

问题已解决,它是由旧库引起的。下载当前版本的MinGW后,它工作正常。

一件立即可见的事情是getline()永远不会返回false,因此循环永远不会终止。它实际上返回ifs并拼写名称空间。有多个版本的
getline
,因此请确保有正确的版本。@JoachimIsaksson:
ifs
被转换为bool,如果流处于错误状态(例如上次操作失败时)。@ybungalobill Cool!新闻给我,谢谢:)我只见过接线员!实际上就是这样…有没有可能得到崩溃的堆栈跟踪?