在抛出 'std::out_of_range' what() 的实例后调用的终止:basic_string::擦除
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::erase
string Farfallino::decode(string buff) {
string stringa;
size_t pos;
while(1) {
while(pos = (buff.find("afa"))) {
buff.erase(pos, 3);
buff.insert(pos, "a");
}
while(pos = (buff.find("efe"))) {
buff.erase(pos, 3);
buff.insert(pos, "e");
}
while(pos = (buff.find("ifi"))) {
buff.erase(pos, 3);
buff.insert(pos, "i");
}
while(pos = (buff.find("ofo"))) {
buff.erase(pos, 3);
buff.insert(pos, "o");
}
while(pos = (buff.find("ufu"))) {
buff.erase(pos, 3);
buff.insert(pos, "u");
}
}
return stringa;
}
我正在尝试擦除传递给函数的字符串中的每个"afa"efe"ifi"ofo"和"ufu",但它给了我这个错误。我不知道我做错了什么。
它应该是这样的:
while ((pos = buff.find("x")) != std::string::npos)
{
// ...
}
"未找到"的信号是返回npos
,而不是零。零只是第一个字符。
相关文章:
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 我收到以下错误:抛出'std::bad_alloc'实例后终止调用
- 对象实例化调用构造函数的次数太多
- 如果 std::vector::clear() 不是静态的,如何在没有实例的情况下调用它?
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- C++中的单例实现在调用 getInstance 函数时不会产生相同的类实例
- 为什么静态数组成员变量在调用对象的实例后不显示任何内容?
- 这个C++编译器优化(在自身的实例上调用对象自己的构造函数)的名称是什么,它是如何工作的?
- 在抛出 'std::runtime_error' 的实例后终止调用 what(): Filebuf 和 ostream 的 I/O 错误
- 从基类实例调用派生类方法而不进行强制转换
- 以下代码如何工作以每次为唯一调用堆栈唯一实例化模板函数?
- 在字符串函数中抛出'char const*'实例后调用的终止
- 如何使用 c++ 从另一个 cpp 文件中的 main.cpp 调用实例化类
- 统一功能使用模板专业化和接口来调用实例和原始类型
- 调用实例化函数时发生链接器错误
- 正在销毁调用实例
- 为什么我可以静态地调用实例函数