c++ - What does string::npos mean? -
this question has answer here:
- what string::npos mean 9 answers
what following statement mean?
string s="joe alan smith""; cout << (s.find("allen") == string::npos) << endl;
actually string::find()
returns position of found string, if doesn't find given string, returns string::npos
, npos
means no position.
npos
unsigned integral value, standard defines -1
(signed representation) denotes no position.
//npos unsigned, why cast needed make signed! cout << (signed int) string::npos <<endl;
output:
-1
see @ ideone : http://www.ideone.com/vrhuj
Comments
Post a Comment