#include #include #include #include #include #include #include #include #include #include using namespace std; #pragma warning (disable:4018) #pragma warning (disable:4996) // provide new ordering (i.e. less than function) class CaseInsensitiveStringCompare { public: bool operator() ( const string & lhs, const string & rhs ) { return stricmp( lhs.c_str( ), rhs.c_str( ) ) < 0; } }; template ostream & operator<< ( ostream & out, const pair & p ) { out << "(" << p.first << "," << p.second << ")"; return out; } template ostream & operator<< ( ostream & out, const vector & v ) { out << "[ "; for( int i = 0; i < v.size( ); i++ ) out << v[ i ] << " "; out << "]"; return out; } template void printCollection( const Collection & c, ostream & out = cout ) { out << "[ "; Collection::const_iterator itr = c.begin( ); while( itr != c.end( ) ) out << *itr++ << " "; out << "]"; out << endl; } map counts( int arr[ ], int N ) { map frequency; for( int i = 0; i < N; i++ ) frequency[ arr[ i ] ]++; return frequency; } template map counts( const vector & arr) { map frequency; for( int i = 0; i < arr.size( ); i++ ) frequency[ arr[ i ] ]++; return frequency; } typedef set MYSTRINGSET; int main( ) { vector v1; v1.push_back( 3 ); v1.push_back( 1 ); v1.push_back( 4 ); sort( v1.begin( ), v1.end( ) ); printCollection( v1 ); list lst1; lst1.push_back( 4.5 ); lst1.push_front( 4.1 ); lst1.push_back( 2.8 ); printCollection( lst1 ); MYSTRINGSET s1; s1.insert( "hello" ); s1.insert( "world" ); s1.insert( "Silly" ); printCollection( s1 ); MYSTRINGSET::iterator itr = s1.find( "SiLlY" ); if( itr == s1.end( ) ) cout << "Find fails" << endl; else cout << *itr << endl; map m1; m1[ "mitch" ] = 3456; m1[ "jane" ] = 7685; cout << "m1 size: " << m1.size( ) << endl; cout << m1[ "mitch" ] << endl; cout << m1[ "chris" ] << endl; cout << "m1 size: " << m1.size( ) << endl; int arr[ ] = { 3, 4, 5, 1, 2, 3, 6, 5, 3, 7, 1, 2, 3 }; printCollection( counts( arr, 13 ) ); ifstream fin( "foo.txt" ); vector v; string str; map > wordMap; int lineNum = 0; string oneLine; while( getline( fin, oneLine ) ) { lineNum++; istringstream is( oneLine ); while( is >> str ) wordMap[ str ].push_back( lineNum ); } printCollection( wordMap ); string str1 = "fgdfhsdaasdkvbd"; cout << str1 << endl; sort( str1.begin( ) + 3, str1.end( ) - 3 ); cout << str1 << endl; printCollection( str1 ); return 0; }