C/C++ Arena

Step 5 of 6

string search and substrings

Handy std::string members:

std::string s = "de_dust2";
s.find("dust");        // 3 (index of first match)
s.find("zz");          // std::string::npos (not found)
s.substr(3, 4);        // "dust" (start, length)
s.substr(3);           // "dust2" (to the end)

Your turn: write std::string map_name(const std::string& s) that strips a prefix ending in the first _. "de_dust2" becomes "dust2"; a string without _ is returned unchanged.

Previous: 2D vectors Next: Challenge: split