Chưa phân loại

I found that we can access to items within a pointer vector by two ways bellow:
The first way is using at function, and the other one is using indexer


#include <iostream>		// For cout
#include <vector>		// For vector

using namespace std;

int main() {

	vector<int>* myVector = new vector<int>;
	myVector->push_back(123);
	myVector->push_back(456);

	cout << myVector->at(0) << endl;

	cout << myVector[0][1] << endl;

	cin.get();

	return 0;
}

The output result is:
123
456

Happy Coding!!

Advertisements
Tagged

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s