Click to See Complete Forum and Search --> : Copying *Specific* Elements From VectorA to VectorB :: C++


kuphryn
02-02-2002, 11:25 AM
Hi.

Let say there are two vectors, vectorA and vectorB.

-----------------------------------------------------
string dataTemp;
std::vector<string> vectorA, vectorB;

for (int = 0; i < 10; ++i)
{
dataTemp += i;
vectorA.push_back(dataTemp);
}

/* The loop above should produce vectorA to look something like this:
0
1
12
123
1234
12345
123456
1234566
12345678
123456789
*/

Okay, vectorB is empty.

I want to copy *specific* elements from vectorA to vectorB.

For example:

vectorB.push_back(vectorA[4]); // Is that right?
vecotrB.push_back(vectorA[8]);

Thanks,
Kuphryn