Vector Error??

This is a discussion on Vector Error?? within the C++ Programming forums, part of the General Programming Boards category; Ok I am getting an error with my cout statement for my vector problem. This problem doesn't look any different ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    17

    Vector Error??

    Ok I am getting an error with my cout statement for my vector problem. This problem doesn't look any different that any other problem that I have done- so maybe I am just loosing it =)

    The error is

    binary '<<' : no operator defined which takes a right-hand operand of type 'class std::vector<int,class std::allocator<int> >' (or there is no acceptable conversion)

    My code is:
    Code:
    #include<iostream>
    #include<string>
    #include<vector>
    using namespace std;
    
    int main () {
    
    	
    	vector <int> v1;
    
    
    	v1.push_back(1);
    	v1.push_back(2);
    	v1.push_back(3);
    	v1.push_back(4);
    	v1.push_back(5);
    	v1.push_back(6);
    	v1.push_back(7);
    	v1.push_back(8);
    
    
    	//v1.insert(v1.begin()+4, 88);
    	//v1.insert(v1.begin()+6, 33);
    
    
    	cout << v1;
    
    	return 0;
    }
    Thanks!!!!!

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    added for and "[]" for accessing element. Dropped string header its not needed.

    Code:
    #include<iostream>
    #include<vector>
    using namespace std;
    
    
    int main () 
    {
    
    	
    	vector <int> v1;
    
    
    	v1.push_back(1);
    	v1.push_back(2);
    	v1.push_back(3);
    	v1.push_back(4);
    	v1.push_back(5);
    	v1.push_back(6);
    	v1.push_back(7);
    	v1.push_back(8);
    
    
    	//v1.insert(v1.begin()+4, 88);
    	//v1.insert(v1.begin()+6, 33);
    
    	for(int x=0; x<v1.size(); x++)
    	{
    		cout << v1[x] <<endl;
    	}
    
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    17
    Thanks for the help!! That makes sense now- you have to look at each spot in the vector and print it out!! Thanks again!!

  4. #4
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    No problem, happy coding!

Popular pages Recent additions subscribe to a feed

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