How to implement 2D vector array?

后端 未结 9 683
你的背包
你的背包 2020-11-29 03:56

I\'m using the vector class in the STL library for the first time. How should I add to a specific row of the vector array?

struct x{
     vector 

        
9条回答
  •  失恋的感觉
    2020-11-29 04:26

    I'm not exactly sure what the problem is, as your example code has several errors and doesn't really make it clear what you're trying to do. But here's how you add to a specific row of a 2D vector:

    // declare 2D vector
    vector< vector > myVector;
    // make new row (arbitrary example)
    vector myRow(1,5);
    myVector.push_back(myRow);
    // add element to row
    myVector[0].push_back(1);
    

    Does this answer your question? If not, could you try to be more specific as to what you are having trouble with?

提交回复
热议问题