#pragma warning (disable: 4786) #include #include #ifdef __GNUC__ #include #else #ifdef __BORLANDC__ #include #else #include #endif #endif #include #include #include using namespace std; ostream & operator<<( ostream & out, const pair > & rhs ) { out << rhs.first << ": " << '\t' << rhs.second[ 0 ]; for( int i = 1; i < rhs.second.size( ); i++ ) out << ", " << rhs.second[ i ]; return out; } int main( int argc, char *argv[ ] ) { if( argc != 2 ) { cerr << "Usage: " << argv[ 0 ] << " filename" << endl; return 1; } ifstream inFile( argv[ 1 ] ); if( !inFile ) { cerr << "Cannot open " << argv[ 1 ] << endl; return 1; } string oneLine; map > concordance; // Read the words; add them to wordMap for( int lineNum = 1; getline( inFile, oneLine ); lineNum++ ) { #if defined( __GNUC__ ) || defined ( __BORLANDC__ ) istrstream st( oneLine.c_str( ), oneLine.length( ) ); #else istringstream st( oneLine ); #endif string word; while( st >> word ) concordance[ word ].push_back( lineNum ); } map >::iterator itr; for( itr = concordance.begin( ); itr != concordance.end( ); itr++ ) cout << *itr << endl; return 0; }