且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C ++中使用std :: string将一个字符替换为另一个字符?

更新时间:2022-11-16 16:46:23

使用 std :: replace 算法:

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

int main()
{
  std::string str = "abccccd";
  std::replace(str.begin(), str.end(), 'c', ' ');
  std::cout << str << std::endl;
}