Since C++20, we now have access to std::string::starts_with
.
If you intend on checking if std::string str1
starts with std::string str2
, you can do the following:
if(str1.starts_with(str2))
{
// code to execute if
// str1 does start with str2
}
For this specific case, it will perform better compared to std::string::find
.