c++ string trim函数实现

#include <string>
#include <algorithm>
#include <functional>

using namespace std;
inline string&  LeftTrim(string   &str)
{
    string::iterator   iter=find_if(str.begin(),str.end(),not1(ptr_fun<int>(::isspace)));
    str.erase(str.begin(),iter);
    return  str;
}

inline  string&  RightTrim(string   &ss) 
{     
    string::reverse_iterator  rev_iter=find_if(str.rbegin(),str.rend(),not1(ptr_fun<int>(::isspace)));
    str.erase(rev_iter.base(),str.end());
    return   str;
}

inline  string&   Trim(string   &st)
{
     return LeftTrim(RigtTrim(st));
}  


 

//参考文档 http://www.cplusplus.com/reference/std/functional/ptr_fun/

你可能感兴趣的:(C++,String,iterator,文档,include)