#include <boost/algorithm/string/predicate.hpp> #include <string> #include <iostream> int main() { std::string mystr = "foobar"; // Prints "true, false" std::cout << std::boolalpha << boost::algorithm::starts_with(mystr, "foo") << ", " << boost::algorithm::starts_with(mystr, "bar") << std::endl; }
Also see: How to use boost string algorithm ends_with: A minimal example