Newbie to C++: How to use pointer to reach the different elements in a row of a vector | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 Answer
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