这是我的代码,但是说replace is not declared in this scope
这不是正确的语法吗?
#include<iostream>
#include<string>
using namespace std;
int main ()
{
string string_to_edit;
cout<<"Enter a string to replace all the vowels:"<<endl;
cin>>string_to_edit;
string output_string=replace(string_to_edit.begin(),string_to_edit.end(),"a","x");
cout<<output_string<<endl;
return 0;
}
您需要#include <algorithm>
for std::replace
,但还需要使用单个字符。请注意单引号:
replace(string_to_edit.begin(),string_to_edit.end(),'a','x');
另请注意,replace
它将替换到位的元素。std::replace
返回void
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句