vector of vector

2019-02-27 05:37发布

问题:

I have the following code fragment

#include <iostream>
#include <ostream>
#include <vector>
using namespace std;

int main() {
    vector<vector<int>>v;
    return 0;  
}

v.push_back(11) does not work what is correct?

回答1:

#include <iostream>
#include <ostream>
#include <vector>
using namespace std;

int main() {
    vector<vector<int> >v;
    vector<int> a;
    a.push_back(11);
    v.push_back(a);
    return 0;  
}

I think this should work right :)



回答2:

vector<vector<int>>v;

needs to be

vector<vector<int> >v;

The consecutive >> acts as the actual >> operator.



标签: c++ vector stl