Saturday, May 22, 2010

std::string::npos

std::string::npos is defined as '-1', even if string::size_type is 'unsigned int'.

For example:
    unsigned char npos = -1;
is valid a valid statement.

std::string::npos could be a different type, such as int. It depends on the compiler.

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis, Addison-Wesley, 1999., p. 495.

No comments:

Post a Comment