Just offer the code you need:
#include <string>
#include <iostream>
using namespace std;
string trim(string str)
{
if(string("") == str) // 不可少,否则有可能出错
{
return str;
}
string s = str.substr(str.find_first_not_of(" "));
return s.substr(0, s.find_last_not_of(" ") + 1);
}
int main()
{
string s = trim(" hello world ");
if(s == string("hello world"))
{
cout << "yes" << endl;
}
else
{
cout << "no" << endl;
}
return 0;
}