C++ vector data() function
Example
Access the memory block used by the vector at index position 1:
vector<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
string* data = cars.data();
cout << data[1];
Try it Yourself »
Definition and Usage
The data()
function returns a pointer to the block of memory where a vector's elements are stored.
Syntax
vector.data();
Parameter Values
None.
Technical Details
Returns: | A pointer to the memory block where the vector's elements are stored. |
---|
Related Pages
Read more about vectors in our Vector Tutorial.
Read more about pointers in our Pointers Tutorial.