[cs33211] string::npos
Mikhail Nesterenko
mikhail at cs.kent.edu
Tue Oct 16 12:03:40 EDT 2012
Please ignore, I sent it to the wrong list.
--
Mikhail
Mikhail Nesterenko wrote:
>
>
> >
> > string b = "Great!"; b.find('g');
> >
> > How can I return string::npos to state that the letter hasn't been found? This didn't work for me: if (!b.find('g')) { return string::npos; }
> >
>
> String find functions that we studied are expected to return the
> position (index of the element) that matches the items searched
> for. What if the item is not found at all? In this case the find
> functions return string::npos. For example:
>
> string b= "Great!";
> if (b.find('x') == string::npos) cout << "no x found\n";
>
> Will print:
>
> no x found
More information about the cs33211
mailing list