0
How do I pick a pointer from a vector of class c++? For example I have a vector a; how do I receive a pointer to only one vector element?
0
How do I pick a pointer from a vector of class c++? For example I have a vector a; how do I receive a pointer to only one vector element?
2
From c++11 you can use the function date. It returns the address of the array used to store the vector elements.
Note that if the vector has no elements, data()
may or may not return nullptr
#include <iostream>
#include <vector>
int main() {
std::vector<int> cheio{1, 2, 3};
std::vector<int> vazio;
cheio.clear();
std::cout << std::boolalpha << "vazio.data() == nullptr? "
<< (vazio.data() == nullptr) << "\n"
<< "cheio.data() == nullptr? "
<< (cheio.data() == nullptr) << "\n";
}
vazio.data() == nullptr? true
cheio.data() == nullptr? false
Browser other questions tagged c++ vector
You are not signed in. Login or sign up in order to post.
This answer is falling under "Low quality publications" due to its size. It could make your answer clearer?
– Don't Panic