为什么我的代码出现"vector subscript out of range"错误?
Why do I get a "vector subscript out of range" error for my code?
为什么我的代码会出现"矢量下标超出范围"错误?
class CSVRow
{
public:
string const& operator[](size_t index) const
{
return m_data[index];
}
size_t size() const
{
return m_data.size();
}
void readNextRow(istream& str)
{
string line;
getline(str, line);
stringstream lineStream(line);
string cell;
m_data.clear();
while (getline(lineStream, cell, ','))
{
m_data.push_back(cell);
}
}
private:
vector<string> m_data;
}
;
istream& operator>>(istream& str, CSVRow& data)
{
data.readNextRow(str);
return str;
}
int main()
{
ifstream file("full_training_dataset.csv");
CSVRow row;
while (file >> row)
cout << row[1] << endl;
return 0;
}
while (file >> row)
cout << row[1] << endl;
First time element would be inserted ar row[0] not at row[1].
相关文章:
- 为什么我的向量::擦除调用会抛出"vector subscript out of range"?
- 解决方案在第 25 行执行错误'out of bounds'
- C++ 向量加减抛出"expression: vector subscript out of range."错误
- 从 MSVC14 切换到 MSVC16 会导致"compiler is out of heap space (C1060)"错误
- 庞大的初始化列表,如何修复"fatal error C1060: compiler is out of heap space"
- 如何解决'vector subscript out of range'错误?
- 在析构函数中调用"delete"运算符时"compiler is out of heap space"编译器错误
- 空集"Out of bound iterator"
- 在 std::unordered_map 中插入新的键/值对会导致"out of range"异常
- 注册 Clang 检查器时出错:"out-of-line-definition of register"
- QList::operator[]中的断言失败<T>:QJoysticks 中的"index out of range"
- 尝试获取矩阵的正确对角线会导致"vector out of range"错误
- 运算符方法和返回对象"out-of-scope"?
- 如何使用 mpi 分散修复"vector subscript out of range"?
- 如何修复邻接列表中的"Debug Assertion Failed" "vector subscript out of range"
- "Vector subscript out of range",在返回声明?
- QList<T>::operator[]: "index out of range" 中的断言失败
- 多次调用存储过程时C++连接器"Commands out of sync" mySQL
- 如何处理C++'index out of bounds error'?
- MySQL 异常"connection lost during query"、"MySQL server has gone away"和"command out of sync"