vector iterator 的使用

// 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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值