vector.push_back(anotherVector)

This is a discussion on vector.push_back(anotherVector) within the C++ Programming forums, part of the General Programming Boards category; im trying to put a vector into another vector using push_back. but its not happening. Code: vector<int> a; vector<int> temp; ...

  1. #1
    Registered User boojus's Avatar
    Join Date
    Oct 2003
    Posts
    9

    vector.push_back(anotherVector)

    im trying to put a vector into another vector using push_back.
    but its not happening.
    Code:
    vector<int> a; vector<int> temp;
    //...//
    temp.push_back(a);

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    push_back takes a single element, not a whole container.

    To append a container to another, use insert:
    Code:
    v1.insert(v1.end(), v2.begin(), v2.end());
    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

  3. #3
    Registered User boojus's Avatar
    Join Date
    Oct 2003
    Posts
    9
    sweet. thank you.

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