Created
February 13, 2012 03:32
-
-
Save xingfuqiu/1813315 to your computer and use it in GitHub Desktop.
C++:Vector及指针的使用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************************/ | |
/* Vector及指针的使用 */ | |
/************************************************************************/ | |
#include "stdafx.h" | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
int main(int argc, char* argv[]) | |
{ | |
vector<int> perr, ferry; | |
vector<int> *pVectArr[2] = {&perr, &ferry}; | |
vector<int> *pPerr = 0; | |
cout << "address of perr:" << &perr << endl; | |
cout << "address of ferry:" << &ferry << endl; | |
for (int i=0; i<20; ++i) | |
{ | |
perr.push_back(i); | |
cout << "address of perr["<<i<<"]= "<<&(perr[i]) << endl; | |
} | |
pPerr = &perr; | |
pPerr->push_back(200); | |
pVectArr[0]->push_back(300); | |
if (pPerr && !pPerr->empty()) | |
{ | |
for (i=0; i<pPerr->size(); ++i) | |
{ | |
cout << "perr["<<i<<"]= "<<(*pPerr)[i]<<endl; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment