Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ std::string指针的Find()方法_C++ - Fatal编程技术网

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()


原因是取消引用(
*
)运算符的优先级低于元素选择(
)运算符的优先级。

这称为运算符优先级,请查看<代码>*
的优先级低于
。这称为运算符优先级,请查看<代码>*的优先级低于