去掉字符串左右两边空格

string from = "   hi from china    ";

from.erase(from.find_last_not_of(' ') + 1, string::npos);   

from.erase(0, from.find_first_not_of(' '));
cout << from << endl; // 输出"hi from china"

你可能感兴趣的:(String)