【发布时间】:2013-08-26 05:39:09
【问题描述】:
我正在尝试找到一种方法来搜索 char 数组中的字符串,然后在每次出现时将其替换为另一个字符串。我很清楚该怎么做,但流背后的整个语法有时会让我感到困惑。无论如何,到目前为止我的代码(而且不是很多)是:
string FindWord = "the";
string ReplaceWord = "can";
int i = 0;
int SizeWord = FindWord.length();
int SizeReplace = ReplaceWord.length();
while ( Memory[i] != '\0')
{
//now i know I can probably use a for loop and
//then if and else statements but im just not quite sure
i++; //and then increment my position
}
我通常不会这么慢:/有什么想法吗?
【问题讨论】:
-
我认为您的意思是字符串而不是流。流完全是另一回事。
-
嗯,是的,我猜是这样,稍后我将在程序中将数组读取到流中。
-
你能把目标也改成std::string吗?