Adding vectors ??

This is a discussion on Adding vectors ?? within the C++ Programming forums, part of the General Programming Boards category; When i last time tried to add vectors i got nasty error (in dev-c++) that opens another file .cpp and ...

  1. #1
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186

    Adding vectors ??

    When i last time tried to add vectors i got nasty error (in dev-c++) that opens another file .cpp and cite the error, a line that has some iterator.

    this is the code

    Code:
    #include <iostream>
    #include <vector>
    using namespace std;
    
    int main()
    {
    	//Making vectors 
    	
    	vector<string> my;
    	my.push_back("Car");
    	my.push_back("Boat");
    	my.push_back("Plane");
    
    	vector<string> yours;
    	yours.push_back("Jet");
    	yours.push_back("Parachute");
    	yours.push_back("Wings");
    
    	vector<string> ours(my, yours);
    
    	return 0;
    }


    plz tell me how to add more than one vector (for example 5 vectors) in one vector ? do i have to specify the size of the vector that is having all the vectors ??

    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,264
    Assuming that you want to combine the two vectors, it would be something like:
    Code:
    vector<string> ours(my);
    ours.insert(ours.end(), yours.begin(), yours.end());
    If you want to create a vector of vectors, then it would be:
    Code:
    vector<vector<string> > ours;
    ours.push_back(my);
    ours.push_back(yours);
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 03:05 PM
  2. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 11:35 AM
  3. Adding Vectors
    By Tonto in forum Game Programming
    Replies: 5
    Last Post: 11-20-2006, 01:06 AM
  4. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 03:44 PM
  5. adding vectors
    By sdchem in forum C++ Programming
    Replies: 2
    Last Post: 04-22-2003, 12:34 PM

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