-
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 ??
:)
-
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);