C ++ STL删除错误 [英] C++ STL remove error

查看:101
本文介绍了C ++ STL删除错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

错误说'remove':function不接受3个参数)

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

推荐答案

尝试添加

#include <algorithm>

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

"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.

这篇关于C ++ STL删除错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆