转帖博客地址 http://www.cnblogs.com/oomusou/archive/2006/11/17/564197.html 下面的函数定义可以将string的前后空白去掉,在处理读入的字符串时非常有用。 std::string& trim(std::string &s) { if (s.empty()) { return s; } s.erase(0,s.find_first_not_of(" ")); s.erase(s.find_last_not_of(" ") + 1); return s; }