字符串C :libc abi.dylib:终止未被发现的类型std :: out_of_range:basic
string c++ : libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string
我正在从文件中阅读。该文件的第一行只是一个数字,第二行是由空格隔开的最多5个数字的序列。我在for循环中有一个if语句,可以循环第二行的长度,但是我的if语句会在行上出现范围错误。我是如此卡住,我已经编辑了很多次,所以我把它留在了我开始的地方。
让我知道您是否需要更多代码。
//Reading from first line of file
prog1.seekg(0, prog1.beg);
prog1 >>fteeth;
prog1 >> fpattern;
for(x=0; x < fteeth; x++){
if ((fpattern.at(x) + 2 < 4) && (fpattern.at(x) + 2 > -1) && (fpattern.at(x) + 3 < 4) && (fpattern.at(x) -3 > -1)){
farray[x] = 2;
}
else {
farray[x] = 1;
}
}
for(x=0; x < fteeth; x++){
cout << farray[x] << endl;
}
}
当索引超出范围时, at
抛出了异常。因此,在循环中使用的x
有问题。
prog1 >> fpattern;
只会读一个"单词",其中" word"是指任何被空格隔开的字符。如果您有五个这样的单词或数字,则必须阅读五次。
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- 在 std::unordered_map 中插入新的键/值对会导致"out of range"异常
- swig perl typemap(out) std::vector<std::string> 在 perl 中不返回所需的输出
- "friend std::ostream& operator<<(std::ostream& out, LinkedList& list)"是什么意思?
- 尝试同时写入 std:out 和文件
- 错误:非静态引用成员"std::ostream&Student::out",无法使用默认赋值运算符
- c ++如何使我.get() std::future out of a vector.
- 如何在 Linux 中将孩子的进程 std (out / err) 设置为父级
- fstream::open() Unicode 或非 ASCII 字符在 Windows 上不起作用(使用 std::ios::out)
- C++同时写入 std::out 和 std:clog
- Printing out std::map
- 将Std::vector通过ref / out从c#传递到c++
- QTextStream and std out
- 聚合'std::stringstream out'具有不完整的类型,无法定义 [C++]
- 以std:: Fstream::in | std:: Fstream::out | std:: Fstream::app