Skip to content

Instantly share code, notes, and snippets.

@xunkai55
Created October 23, 2015 06:18
Show Gist options
  • Save xunkai55/1e36a0160ad568498d20 to your computer and use it in GitHub Desktop.
Save xunkai55/1e36a0160ad568498d20 to your computer and use it in GitHub Desktop.
move a vector from a vector2D to another one
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
void PrintVec2D(vector<vector<int>> &d) {
for (int i = 0; i < d.size(); i++) {
cout << "subvec " << i << ": ";
for (int j = 0; j < d[i].size(); j++)
cout << d[i][j] << " ";
cout << endl;
}
}
int main() {
vector<vector<int>> t;
vector<vector<int>> d;
t.resize(5);
d.resize(1);
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 3; j++)
t[i].push_back(i + j);
}
for (auto &f: t) {
cout << "src" << endl;
PrintVec2D(t);
d[0] = move(f);
cout << "des" << endl;
PrintVec2D(d);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment