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

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -

c++ - Warning : overflow in implicit constant conversion -