Thread: stl vector + iterator operation

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    24

    stl vector + iterator operation

    I wrote a simple 'base' class and I then had a vector of 'base' objects.I then created 10 base objects.I then wanted to ouput the contents of it using a iterator.How do i do it? i get error.

    Code:
    class base{  /*simple base class*/
    private:
    	int status;
    public:
    	int getStatus(){
    		return status;
    	}
    	base(int num){
    		status =num;
    	}
    };
    
    int main(void){
    
    	vector<base> the_vector;
    	vector<base>::iterator the_iterator;
    
    	/*INPUT AND CREATE BASE OBJECTS OF VALUES 1 to 10*/
    	for( int i=1; i < 11; i++ ){
    		base a(i);
    		the_vector.push_back(a);
    	}
    	
    	/*OUTPUT 1 to 10*/
    	the_iterator = the_vector.begin();
    	while( the_iterator != the_vector.end() ) {
    		cout<<the_vector.getStatus()<<endl;  //ERROR LINE
    		the_iterator++;
    	}
    }
    it must be a silly error i guess.
    thanx

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    the_iterator->getStatus()

    And the standard way to iterate over a container is
    Code:
    for(iterator_type it = container.begin(); it != container.end(); ++it) {
    }
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Formatting Using STL
    By ChadJohnson in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2004, 05:52 PM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. STL or no STL
    By codec in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2004, 02:36 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM