0

Newbie to C++: How to use pointer to reach the different elements in a row of a vector

Suppose I have the following code: vector<vector<int>> entries; for (int i = 0; i < 5; ++i) { vector<int> temp = { 1,2,3,5 }; entries.push_back(temp); } int* entry_1; vector<int*> entry_2; for (int i = 0; i < 5; ++i) { entry_2.push_back(&entries[i][0]); } entry_1 = entry_2[0]; cout << *(entry_1[1]++) << endl; Actually I want to reach the value of "entries"(vector of a vector) in the second-row second-column (if we visualize the "entries" into a table) only through the pointer: entry_1. What should I do? (Btw Sorry for my poor english)

27th Mar 2020, 2:08 PM
æ±éąšç•™ć
æ±éąšç•™ć - avatar
1 RĂ©ponse
0
Martin Taylor Thank u very much! but I still want to find a way to combine pointer with vector
27th Mar 2020, 5:10 PM
æ±éąšç•™ć
æ±éąšç•™ć - avatar