None of them are correct.
The member function sub
does not exist for string, unless you are using another string
class that is not std::string
.
The second one of the first question subString = &anotherString.sub(9);
is not safe, as you're storing the address of a temporary. It is also wrong as anotherString
is a pointer to a string object. To call the sub
member function, you need to write anotherString->sub(9)
. And again, member function sub
does not exist.
The first one of the second question is more correct than the second one; all you need to do is replace "\""
with '\"'
.
The second one of the second question is wrong, as:
doubleQuote
does not refer to the 10th character, but the string from the 10th character onwards
doubleQuote == "\""
may be type-wise correct, but it doesn't compare equality of the two strings; it checks if they are pointing to the same thing. If you want to check the equality of the two strings, use strcmp.