Programming Tips - C++: Make a std::string startsWith()

Date: 2024jan22 Language: C++ Q. C++: Make a std::string startsWith() A. Before C++20
inline bool startsWith(const std::string &str, const std::string &target) { return str.rfind(target) == 0; } if (startsWith(mystr, "http:")) { ... }
Since C++20
if (mystr.starts_with("http:")) { ... }
More info https://en.cppreference.com/w/cpp/string/basic_string/starts_with