How to check if a string starts or ends with a certain substring?
Show answer and explanation
Since C++20, std::string and std::string_view provide starts_with and ends_with. Before that, compare a prefix at position zero and compare the suffix only after checking that the source is at least as long as the suffix.
Since C++20, std::string and std::string_view provide starts_with and ends_with. Before that, compare a prefix at position zero and compare the suffix only after checking that the source is at least as long as the suffix.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.