【初心者歓迎】C/C++室 Ver.49【環境依存OK】
■ このスレッドは過去ログ倉庫に格納されています
0691デフォルトの名無しさん
2008/02/25(月) 14:12:57これでいいのか?
#include <string>
#include <iostream>
using namespace std;
void replace(string& str, string p, string q)
{
int i = str.find(p);
while (i >= 0) {
str.replace(i, p.length(), q);
i = str.find(p, i + q.length());
}
}
int main()
{
string str = "abcdabcd";
replace(str, "bc", "BC");
cout << str << endl;
}
■ このスレッドは過去ログ倉庫に格納されています