std::string 的几种用法
toupper, tolower
transform(s.begin(), s.end(), s.begin(), toupper);
transform(s.begin(), s.end(), s.begin(), tolower);
------------------------------------------------------------------------
trim
s.erase(0, s.find_first_not_of(" \n"));
s.erase(s.find_last_not_of('' '') + 1);
-----------------------------------------------------------------------
erase
s.erase(remove_if(s.begin(),s.end(),
bind2nd(equal_to<char>(), '' '')),
s.end());
-----------------------------------------------------------------------
replace
s.replace(s.find(sub), sub.size(), strRep);
-----------------------------------------------------------------------
startwith, endwith
bool startwith = s.compare(0, head.size(), head) == 0;
bool endwith = s.compare(s.size() - tail.size(), tail.size(), tail) == 0;
------------------------------------------------------------------------
toint, todouble, tobool...
atoi(s.c_str());
stringstream(s) >> ii;
atof(sd.c_str());
------------------------------------------------------------------------
浙公网安备 33010602011771号