[英]error: cannot convert 'std::basic_string<char>::iterator ...' to 'const char* for argument '1' ...'
I'm getting the following error:我收到以下错误:
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*)'
For some reason, my program compiles perfectly when I'm working on a Mac... but once I use a Linux machine, this error pops up in more than one place.出于某种原因,当我在 Mac 上工作时,我的程序编译完美……但是一旦我使用 Linux 机器,这个错误就会在不止一个地方弹出。
Here's one of the instances where the error pops up:这是弹出错误的实例之一:
SomeClass::SomeClass(string t, string art, Time dur) {
char chars[] = ",";
t.erase(std::remove(t.begin(), t.end(), chars[0]), t.end());
art.erase(std::remove(art.begin(), art.end(), chars[0]), art.end());
// Some more code ...
}
More specifically, the error is coming from this line:更具体地说,错误来自这一行:
t.erase(std::remove(t.begin(), t.end(), chars[0]), t.end());
Does anyone know how to approach this problem?有谁知道如何解决这个问题?
You forgot to #include <algorithm>
, where std::remove
is located.您忘记了
#include <algorithm>
,其中std::remove
位于。 Without that, your compiler only knows about this std::remove
(I get the same error with Visual C++ 14), which is defined in indirectly included <cstdio>
header.如果没有它,您的编译器只知道这个
std::remove
(我在 Visual C++ 14 中遇到了同样的错误),它是在间接包含的<cstdio>
标头中定义的。
Different behavior among compilers is a result of different #include
hierarchies of the standard library implementations.编译器之间的不同行为是标准库实现的不同
#include
层次结构的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.