// 2008test.cpp: 主项目文件。
使用iterator遍历,使用iterator还可以方便地进行vector的删除
#include "stdafx.h"
#include "stdio.h"
#include <vector>
using namespace std;
//using namespace System;
class A
{
public:
int a;
int b;
};
double * test()
{
//double c[4]={1.0,0.0,0.0,1.0};
double * c = new double[4];
return c;
}
int main(array<System::String ^> ^args)
{
printf("hello test!");
//Console::WriteLine(L"Hello World");
vector <A *>alist;
A * a ;
a = new A;
a->a = 1;
a->b = 1;
alist.push_back(a);
a = new A;
a->a = 3;
a->b = 2;
alist.push_back(a);
a = new A;
a->a = 2;
a->b = 3;
alist.push_back(a);
vector<A *>::iterator ai;
for (ai= alist.begin();ai!=alist.end();ai++)
{
int c = (*ai)->a+(*ai)->b;
printf("/n%d:/t%d+%d=%d",ai-alist.begin(),(*ai)->a,(*ai)->b,c);
}
double * p = test();
printf("/n%f",p[3]);
return 0;
}
删除:
vector<int>::iterator head;
vector<int> queue;
head = queue.begin();
ptid = *head;
queue.erase(head);