首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Fstream _Fgetc访问冲突

Fstream _Fgetc访问冲突
EN

Stack Overflow用户
提问于 2012-01-23 02:37:04
回答 1查看 543关注 0票数 0

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

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

我使用的是:

代码语言:javascript
复制
#include <vector>
#include <istream>
#include <fstream>
#include <string>

我的函数:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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,但是我如何控制将使用哪个函数呢?

编辑:从堆栈中提取:

代码语言:javascript
复制
>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++
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-24 22:23:53

问题解决了,这是由旧的库造成的。下载当前版本的MinGW后,它可以正常工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8963559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档