繁体   English   中英

Fstream _Fgetc访问冲突

[英]Fstream _Fgetc access violation

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

我认为,文件指针可能为null,但我能用它做什么? 或者,我的功能错了吗? 想念我的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;
}

来自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);
    }
}

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++

问题解决了,它是由旧图书馆引起的。 下载当前版本的MinGW后,它可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM