【发布时间】:2018-06-19 22:33:52
【问题描述】:
在使用getline 函数后尝试获取第一个字母时,我不断收到 Unhandled 异常。
错误:
Lab2 中 0x7535DB52 处的未处理异常 - 容器和 Regex.exe: Microsoft C++ 异常:内存位置的 std::out_of_range 0x00B5F43C。
class CodeMap
{
private:
vector<string> code;
vector<char> character;
public:
CodeMap() { character.resize(11000); }
~CodeMap() {};
void setChar(string filename)
{
string fileName = filename;
ifstream fin;
fin.open(fileName.c_str());
string line = " ";
char codeChar;
while (!fin.eof())
{
getline(fin, line);
codeChar = line.at(0); //Unhandled exception, tried to use [] instead, still error.
}
fin.close();
}
我想知道这里发生了什么。
无论如何要解决这个问题?
感谢您的帮助。
【问题讨论】:
-
eof() cluster-ef 没那么重要,解析文本文件时的样板文件总是跳过空行。