Thread: vector.push_back(anotherVector)

  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,895
    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