What does the phrase std::string::npos mean in the following snippet of code?
found = str.find(str2);
if (found != std::string::npos)
std::
An answer for these days of C++17, when we have std::optional:
If you squint a bit and pretend std::string::find() returns an std::optional (which it sort of should...) - then the condition becomes:
auto position = str.find(str2);
if ( position.has_value() ) {
std::cout << "first 'needle' found at: " << found.value() << std::endl;
}