Fstream_Fgetc访问冲突
Fstream _Fgetc access violation
我想用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;
}
_导致异常的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后,它可以正常工作。
相关文章:
- 写入位置0x0000000C时发生访问冲突
- 引发异常:读取访问冲突**dynamicArray**为0x1118235.发生
- 链表中写入访问冲突的未知原因
- C++中的openCV Mat访问冲突
- C++尝试深度复制唯一指针时出现内存访问冲突
- C++ 中动态二维数组的访问冲突
- 从嵌套循环中的 std::list 中删除将返回访问冲突
- 写入访问冲突异常
- 在类 12.exe 中0x7B37FF80 (ucrtbased.dll) 引发异常: 0xC0000005:访问冲突读
- 0xC0000005:访问冲突写入位置0xCDCDCDCD动态分配错误
- 读取访问冲突.这0xCDCDCDCD
- 0xC0000005:访问冲突读取位置 0x00000000. 重载 == 运算符的问题
- 插入数组时违反写访问冲突
- 使用 ReadProcessMemory 获取字符串值的访问冲突
- 尝试通过共享指针使用变量时读取访问冲突
- 堆栈上的 C++ 访问冲突写入异常
- 引发异常:写访问冲突. temp 为 nullptr
- 将静态字符数组中的字符分配给动态分配的字符数组 - 访问冲突
- 在C++中删除双向链表的头节点后出现访问冲突异常
- C++ 读取访问冲突,0xCDCDCDCD