C++ std::string指针的Find()方法
我有这样一个函数:C++ std::string指针的Find()方法,c++,C++,我有这样一个函数: int find_string ( string *url){ if(*url.find() != string::npos){ [...] } [...] } 这样说吧: find_string(&url); 但我得到了以下编译错误: request for member ‘find’ in ‘url’, which is of non-class type ‘std::string*’ 为什么会发生这种情况,最重要的是,我如
int find_string ( string *url){
if(*url.find() != string::npos){
[...]
}
[...]
}
这样说吧:
find_string(&url);
但我得到了以下编译错误:
request for member ‘find’ in ‘url’, which is of non-class type ‘std::string*’
为什么会发生这种情况,最重要的是,我如何修复这种情况?(当没有指针时,它正在工作)使用(*url).find()
或者更好的url->find()
*url.find
尝试调用find()
函数,然后使用操作符*
使用(*url.find()
或者更好的url->find()
*url.find
尝试调用find()
函数,然后使用操作符*
*url.find()
相当于*(url.find())
,而实际需要的是(*url).find()
。更好的是,您应该使用url->find()
原因是取消引用(*
)运算符的值低于元素选择(
)运算符。*url.find()
相当于*(url.find())
,而实际需要的是(*url.find>)。更好的是,您应该使用url->find()
原因是取消引用(*
)运算符的优先级低于元素选择(
)运算符的优先级。这称为运算符优先级,请查看<代码>*
的优先级低于
。这称为运算符优先级,请查看<代码>*的优先级低于
。