vector<string> MyStrings;
vector<string>::iterator ItStr;
I'm using c_str() to return the pointer to the string.
Why does it need to be dereferenced with parentheses?
Doesn't compile: *ItStr.c_str();
error C2039: 'c_str' : is not a member of 'std::vector<_Ty>::iterator'
Compiles/Works with parentheses around iterator: (*ItStr).c_str();
If you could point me (no pun intended) in the right direction I would appreciate it.Thanks!
Because the .
operator has precedence over the *
operator. See this link
.
has higher precedence than the unary *
.
*ItStr.c_str()
is as if you had said *(ItStr.c_str())
.
You can, of course, just use ItStr->c_str()
, since (*x).y
is equivalent to x->y
(at least for pointers and iterators; you can, of course, overload the operators for your own types such that they are not consistent, but you'd be crazy to do so).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With