所以我有一个任务将一个字符串中的某个字的所有出现转换为另一个字符串。但与while循环的条件问题,这使得这个错误std :: out_of_range当使用字符串查找和替换内循环
终止叫做抛出“的std :: out_of_range”
什么()的一个实例后:basic_string的::替换
此应用程序已经要求运行时以不寻常的方式终止它。请联系应用程序支持团队以获取更多信息。流程返回3段(0x3)执行时间:2.751小号
我的代码是:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str2("three");
string str("one three two four three three");
while (str.find(str2) != NULL){
str.replace(str.find(str2),str2.length(),"five");
cout << str << endl; // i put it inside loop to see output
}
cout << str << endl;
return 0;
}
有什么建议?
感谢您的帮助。 – DoktorD96