std::string trim (const std::string& src, const std::string& space = " \t\r\n")
{
    std::string::size_type b = src.find_first_not_of(space);
    return src.substr(b, src.find_last_not_of(space) - b);
}

最発明ってほどのことでもないだろ