我正在尝试实现一个算法,我想将用户输入的元素输入到 2D 向量中,以便我有一个这样的元素:
reference 1:
1 2 3
3 2 1
1 2 3
Run Code Online (Sandbox Code Playgroud)
所以我想知道如何将元素推回二维向量
我的问题在这里:
std::vector<vector<int>> d;
//std::vector<int> d;
cout<<"Enter the N number of ship and port:"<<endl;
cin>>in;
cout<<"\Enter preference etc..:\n";
for(i=0; i<in; i++){
cout<<"ship"<<i+1<<":"<<' ';
for(j=0; j<in; j++){
cin>>temp;
d.push_back(temp);// I don't know how to push_back here!!
}
}
Run Code Online (Sandbox Code Playgroud)