Skip to content

Instantly share code, notes, and snippets.

@xingfuqiu
Created February 13, 2012 03:32
Show Gist options
  • Save xingfuqiu/1813315 to your computer and use it in GitHub Desktop.
Save xingfuqiu/1813315 to your computer and use it in GitHub Desktop.
C++:Vector及指针的使用
/************************************************************************/
/* 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