去掉字符串左右两端空白字符串

#include <functional>
#include <algorithm>

using namespace std;

string& lTrim(string &ss)
{
    string::iterator p=find_if(ss.begin(),ss.end(),not1(ptr_fun(isspace)));
    ss.erase(ss.begin(),p);
    return ss;
}
string& rTrim(string &ss)
{
    string::reverse_iterator  p=find_if(ss.rbegin(),ss.rend(),not1(ptr_fun(isspace)));
    ss.erase(p.base(),ss.end());
    return ss;
}
string& trim(string &st)
{
    lTrim(rTrim(st));
    return st;
}

  此 为网上找的,原文不知道在哪,就不给出链接了。保存以后备用。

posted @ 2012-10-13 22:02  天天520  阅读(414)  评论(0编辑  收藏  举报