14

I'm having trouble understanding where I went wrong with my code:

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

The error says "'remove': function does not take 3 arguments (C2660)"

3
  • 7
    You were ending up calling this function instead.
    – Jon
    Dec 6, 2011 at 1:55
  • 4
    +1 for providing a complete minimal example program. sscce.org
    – Robᵩ
    Dec 6, 2011 at 1:55
  • 2
    @Jon: Nice catch. That's why I prefer not to use using namespace std as it hides all manner of functions.
    – johnsyweb
    Dec 6, 2011 at 1:58

1 Answer 1

26

Try adding

#include <algorithm>

"algorithm" is an STL header containing a lot of functions, including std::remove, which the OP is trying to call. The error he got was because there is another function that takes a single argument, called "remove", which deletes a file.

6
  • Gotta wait 10 minutes before I can! Dec 6, 2011 at 1:57
  • @StilesCrisis I think you should explain what <algorithm> is, then you'll get also +1 from me :) Dec 6, 2011 at 1:58
  • I know what <algorithm> is, I just forgot completely about it! But yes, that would be a good idea for other people. Dec 6, 2011 at 1:59
  • 3
    @StilesCrisis Use comment of Jon to make your answer even better. Dec 6, 2011 at 2:01
  • 1
    @StilesCrisis I know it. That was merely to make the answer better. +1 Dec 6, 2011 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.