错误:不能将'std :: basic_string< char> :: iterator ...'转换为'const char *'参数'1'...' [英] error: cannot convert 'std::basic_string<char>::iterator ...' to 'const char* for argument '1' ...'
问题描述
我收到以下错误:
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*)'
由于某种原因,我的程序编译完美,当我在Mac上工作...但一旦我使用Linux机器,这个错误弹出在多个地方。 (如果任何人可以解释为什么会发生这种情况,那就太棒了!)
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. (If anyone could explain why this occurs, that would be great!)
这里是其中一个错误弹出的实例:
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 ...
}
错误来自此行:
t.erase(std::remove(t.begin(), t.end(), chars[0]), t.end());
有没有人知道如何解决这个问题?
Does anyone know how to approach this problem?
推荐答案
您忘记了 #include< algorithm>
找到了一个href =http://en.cppreference.com/w/cpp/algorithm/remove> std :: remove
。否则,您的编译器只知道此 std :: remove
You forgot to #include <algorithm>
, where std::remove
is located. 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.
编译器中不同的行为是标准库实现的不同 #include
层次结果。
Different behavior among compilers is a result of different #include
hierarchies of the standard library implementations.
这篇关于错误:不能将'std :: basic_string< char> :: iterator ...'转换为'const char *'参数'1'...'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!