0
我以为我会做一个程序,需要一个文件的语法如下:old_word:new_word
使语法的变化更容易。我还有其他计划,但现在这个计划的核心工作并不成功。
我没有使用C++非常长,所以我仍然在学习的问题
。我正在使用别人的字符串替换函数,但它陷入了无限循环。该函数包含一些我不熟悉的语法,所以我不知道它为什么失败。其他每个函数都能正确返回
的字符串替换功能如下:
//!Not my work
void replaceAll(std::string& str, std::string& from, std::string& to) {
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) < std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
}
该程序在此循环失败:
for(int secInd=0; secInd<members; secInd++)
{
replaceAll(line[index],toStrings[secInd],fromStrings[secInd]);
}
line
距离getline
函数获得的缓冲器。 toStrings
是从语言定义文件加载的,而fromStrings也是如此。
有人可以告诉我为什么这将进入一个无限循环,并可能告诉我如何解决它?如果您需要它,整个来源位于http://pastebin.com/zXFFvUSm。
将
抓住调试器! –
不,StackOverflow不是一个人力调试器。 –