C++ STL删除错误

tr0*_*ing 11 c++ string stl

我无法理解我的代码出错的地方:

#include <iostream>

#include <string>

using namespace std;

int main(int argc, char* argv[]) {
    string str = "";
    cin >> str;
    remove(str.begin(), str.end(), ' ');
    cout << str;
    cin.ignore();
}
Run Code Online (Sandbox Code Playgroud)

错误说"'删除':函数不带3个参数(C2660)"

Sti*_*sis 19

尝试添加

#include <algorithm>
Run Code Online (Sandbox Code Playgroud)

"algorithm"是一个包含很多函数的STL头文件,包括OP试图调用的std :: remove.他得到的错误是因为有另一个函数接受一个名为"remove"的参数,它删除了一个文件.

  • 请单击复选框将此问题标记为已回答. (6认同)
  • @StileCrisis使用Jon的评论让你的答案更好. (3认同)