gpt4 book ai didi

c++ - 我有编译器的情况。当我运行代码以去除一串特殊字符时,它在一个编译器中运行但在另一个编译器中不运行?

转载 作者:搜寻专家 更新时间:2023-10-31 01:46:58 25 4
gpt4 key购买 nike

这是在 g++ 4.6.3 中产生错误的代码

for (int i = 0; i < strlen(chars); i++)
{
a.erase (remove(a.begin(), a.end(), chars[i]), a.end());
}

我得到的错误是

error: cannot convert 'std::basic_string<char>::iterator {aka __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >}' to 'const char*' for argument '1' to 'int remove(const char*)'

代码在代码块 12.11 中运行良好。

最佳答案

你需要

#include <algorithm>

并使用 std::remove 而不是 remove

否则它会尝试使用 remove 函数,该函数对删除文件很有用,它接受 const char* 作为参数。

关于c++ - 我有编译器的情况。当我运行代码以去除一串特殊字符时,它在一个编译器中运行但在另一个编译器中不运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19934587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com