【问题标题】:C++ STL remove errorC++ STL 删除错误
【发布时间】:2012-01-13 17:30:12
【问题描述】:

我无法理解我的代码哪里出错了:

#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();
}

错误提示“'remove': function does not take 3 arguments (C2660)”

【问题讨论】:

  • 你最终调用了this 函数。
  • +1 用于提供完整的最小示例程序。 sscce.org
  • @Jon:不错的收获。这就是为什么我不喜欢使用using namespace std,因为它隐藏了各种功能。

标签: c++ string stl


【解决方案1】:

尝试添加

#include <algorithm>

"algorithm" 是一个 STL 标头,其中包含许多函数,包括 OP 试图调用的 std::remove。他得到的错误是因为有另一个函数需要一个参数,称为“remove”,它会删除一个文件。

【讨论】:

  • 我得等 10 分钟才可以!
  • @StilesCrisis 我认为你应该解释一下&lt;algorithm&gt; 是什么,然后你也会得到我的 +1 :)
  • 我知道 是什么,我只是完全忘记了它!但是,是的,这对其他人来说是个好主意。
  • @StilesCrisis 使用 Jon 的评论让你的答案变得更好。
  • @StilesCrisis 我知道。那只是为了使答案更好。 +1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-08
  • 1970-01-01
  • 1970-01-01
  • 2011-09-29
相关资源
最近更新 更多