我想从Stroustup的书中测试search()
的示例。返回类型为std :: search()
string quote("why waste time learning, when ignorance is instantaneous?");
bool in_quote(const string& s){
char* p = search(quote.begin(), quote.end(), s.begin(), s.end());
return p != quote.end();
}
void test(){
bool b1 = in_quote("learning"); // b1=true
bool b2 = in_quote("lemming"); // b2=false
}
,但我得到了以下错误:
error C2440: 'initializing' : cannot convert from
'std::_String_iterator<_Elem,_Traits,_Alloc>' to 'char *'
它看起来像返回类型是不正确的。我也试过string::iterator
,并得到了同样的错误。那么,什么应该是正确的类型,它应该是容器的迭代器类型?由于
如果您有C++ 11,请使用'auto'。但它看起来应该是'std :: string :: iterator'。当你尝试那个时,什么信息?它应该是一个不同的信息。 –
@ubbdd迭代器不是**指针。 – Mahesh
打开“输出”窗口查看_full_消息的方式。它应该告诉你那里有'_Elem'的类型 –