Help with displaying output

This is a discussion on Help with displaying output within the C++ Programming forums, part of the General Programming Boards category; Code: // Output the cross reference. void Xref::generateCrossReference( ) { typedef map<string,list<int>, less<string> > MapType; typedef MapType::const_iterator MapIteratorType; MapType xrefMap; ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    32

    Help with displaying output

    Code:
    // Output the cross reference.
    void Xref::generateCrossReference( )
    {
        typedef map<string,list<int>, less<string> > MapType;
        typedef MapType::const_iterator MapIteratorType;
    
        MapType xrefMap;
        string current;
    
          // Insert identifiers into the map.
        while( ( current = tok.getNextID( ) ) != "" )
            xrefMap[ current ].push_back( tok.getLineNumber( ) );
    
          // Iterate through map and output
          // identifiers and their line number.
        MapIteratorType itr;
        for( itr = xrefMap.begin( ); itr != xrefMap.end( ); ++itr )
        {
            const list<int> & theLines = (*itr).second;
            list<int>::const_iterator lineItr = theLines.begin( );
            list<int>::const_iterator demo = theLines.begin( );
            list<int>::const_iterator beg = theLines.begin( );
            list<int>::const_iterator end = theLines.begin( );
            
                   
              // Print identifier and first line where it occurs.
            cout << (*itr).first << ": " << *lineItr;
    		
    	     
            // Print all other lines where the word exists
            
            for( ++lineItr; lineItr != theLines.end( ); ++lineItr )
                if(*lineItr == *demo)
                  {
                  	cout << "";
                  }
               
               else if (*lineItr - *demo == 1)
                  {
                   while(*lineItr - *--lineItr == 1)
                     {
                      lineItr++;	
                     }
                  cout << "-" << *lineItr;
                  
                  }	
              else 
               {
                cout << ", " << *lineItr;
                ++demo;
               }
            cout << endl;
        }
    }
    I've been working with the Cross-Reference Generator. For example, if I had a simple file with the first 3 lines of it containing the word 'test', the output would be test: 1, 2, 3. I modified it so that if the word appears on the same line more than once than it only prints the line number once. I am now working on, and having trouble with, displaying the range for words that appear on consecutive lines. For example, I want the output to be test: 1-3 and not test: 1, 2, 3. The else if statement I have at the bottom is what I have come up with and I know is totally wrong, so could someone help me and point me in the right direction? Thanks for any help.

  2. #2
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    I think there are minimum() and maximum functions. So, if you have a group of numbers, such as, 13,14,15,16 , would search through the group and find the minimum and then maximum.

    minimum() "-" maximum()

    EDIT, I just remembered the functions are max() and min(). However, you could easily make your own maximum and minimum functions.
    Last edited by Sentral; 03-28-2007 at 07:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. displaying a array to output
    By gkoenig in forum C Programming
    Replies: 19
    Last Post: 02-11-2008, 04:18 AM
  2. strange virtual function output
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 02-08-2008, 08:08 AM
  3. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 06:41 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 06:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21