Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 用c+中的另一个ascii字符替换一个ascii字符的所有实例+;?_C++ - Fatal编程技术网

C++ 用c+中的另一个ascii字符替换一个ascii字符的所有实例+;?

C++ 用c+中的另一个ascii字符替换一个ascii字符的所有实例+;?,c++,C++,可能重复: 例如,我有一个字符串“Hello World”,我想用“1”s替换所有的“l”。我该怎么做?我是C++新手。我的大部分背景都是Python,在Python中,您可以只使用.replace方法。使用std::replace #include <string> #include <algorithm> #include <iostream> int main() { std::string str = "Hello World";

可能重复:


例如,我有一个字符串“Hello World”,我想用“1”s替换所有的“l”。我该怎么做?我是C++新手。我的大部分背景都是Python,在Python中,您可以只使用.replace方法。

使用
std::replace

#include <string>
#include <algorithm>
#include <iostream>

int main() {
    std::string str = "Hello World";
    std::replace(str.begin(),str.end(),'l','1');
    std::cout << str; //He11o Wor1d
}
#包括
#包括
#包括
int main(){
std::string str=“Hello World”;
替换(str.begin(),str.end(),'l','1');

std::cout使用
std::replace

#include <string>
#include <algorithm>
#include <iostream>

int main() {
    std::string str = "Hello World";
    std::replace(str.begin(),str.end(),'l','1');
    std::cout << str; //He11o Wor1d
}
#包括
#包括
#包括
int main(){
std::string str=“Hello World”;
替换(str.begin(),str.end(),'l','1');

std::cout+1对我来说是好的解决方案!+1对我来说是好的解决方案!