// 文字列の前方WhiteSpaceを削除する。 // MFCの CString::TrimLeft()みないな.. #include <iostream> #include <string> using namespace std; // ret 0 : normal int trim_left( string &str ) { string::size_type pos = str.find_first_not_of( " \t" ); if ( pos == str.npos ) { // not found return 1; } if ( pos == 0 ) { // hit , but first. return 1; } str.erase( 0, pos ); return 0; } int main() { string szStr = " \t hogehogeahihaslajfd"; cout << ":" << szStr << ":" << endl; trim_left( szStr ); cout << "string is :" << szStr << ":" << endl; return 0; } /* 指定文字群以外の文字が前方から検索して( find_first_not_of() )、 最初に現れる位置を知る。 それ以前を削除( erase() )すれば、trim_leftのできあがり。 */ // end of file