Cannot understand how the following code works.
String::npos
I cannot figure out how does it works. Please anyone help me out with that.
Cannot understand how the following code works.
String::npos
I cannot figure out how does it works. Please anyone help me out with that.
std::string::npos returns an integer value (-1) which is used to determine whether or not a value is inside a string.
In the example provided here: https://en.cppreference.com/w/cpp/string/basic_string/npos you see the author uses .find('a') to find 'a' char inside the string "test". Because the char 'a' does not hold a position in the string (npos literally translates to no position) it returns -1.