#include #include #include #include #include using namespace std; inline vector split( const string& s, const string& f ) { vector temp; if ( f.empty() ) { temp.push_back( s ); return temp; } typedef string::const_iterator iter; const iter::difference_type f_size( distance( f.begin(), f.end() ) ); iter i( s.begin() ); for ( iter pos; ( pos = search( i , s.end(), f.begin(), f.end() ) ) != s.end(); ) { temp.push_back( string( i, pos ) ); advance( pos, f_size ); i = pos; } temp.push_back( string( i, s.end() ) ); return temp; } int main() { const vector test( split( "1,2,3,4,5,6,7,8,9", "," ) ); copy( test.begin(), test.end(), ostream_iterator(cout, "\n" ) ); } /* g++ -Wall -Wextra this.cpp -o this -O3 -mtune=i686 -s */