vector - STL C++

vector<X, A>::data()

Declaration

const_pointer vector<X,A>::data() const;

Description

This is the data() function for the vector class template.

Header Include

#include <vector>

Overloads

pointer vector<X,A>::data();

Example

#include <iostream>
#include <vector>

int main()
{
	using namespace std;

	// Create a vector instance
	vector<char> qV;
	qV.push_back('X');
	qV.push_back('o');
	qV.push_back('a');
	qV.push_back('X');
	qV.push_back('.');
	qV.push_back('n');
	qV.push_back('e');
	qV.push_back('t');

	// The data() function returns a pointer to the first entry.
	// We can use either a pointer or const_pointer.
	vector<char>::pointer qConstPtr= qV.data();
	vector<char>::const_pointer qPtr = qV.data();

	cout << "const pointer points to: " << *qConstPtr << endl;
	cout << "pointer points to: " << *qPtr << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

vector<X, A>::data() Output
 

© 2007–2025 XoaX.net LLC. All rights reserved.