参见:https://zh.cppreference.com/w/cpp/algorithm/remove

 

使用 erase 和 remove 配合。

#include <algorithm>
#include <string>
#include <iostream>
#include <cctype>
 
int main()
{
    std::string str1 = "Text with some   spaces";
    str1.erase(std::remove(str1.begin(), str1.end(), ' '),
               str1.end());
    std::cout << str1 << '\n';
}

输出结果是:

Textwithsomespaces

 

相关文章:

  • 2022-12-23
  • 2022-02-05
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
  • 2021-10-27
猜你喜欢
  • 2021-05-25
  • 2021-12-02
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案