c++ - What does string::npos mean? -


this question has answer here:

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

Popular posts from this blog

mod rewrite - Doing external redirect. .htaccess NS flag not working. How to achieve similar results? -

mysql - How to insert just year and month into date field? -