//每次写代码总是被迭代器的iter->和*iter弄晕,主要是被protobuf弄晕了

#include <vector>

struct test{
test(){
memset(this, , sizeof(test));
}
int a;
int b;
}; int main()
{
test a, b;
a.a = a.b = ;
b.a = b.b = ; //std::vector<test> vecT;
//vecT.push_back(a);
//vecT.push_back(b);
//for (std::vector<test>::iterator it = vecT.begin(); it != vecT.end(); ++it)
//{
// int v_a = it->a;//直接访问元素中的成员
// int v_b = it->b; // v_a = (*it).a;//(*it)直接就是vector中的保存的元素
// v_b = (*it).b;
//} std::vector<test*> vecT;
vecT.push_back(&a);
vecT.push_back(&b);
for (std::vector<test*>::iterator it = vecT.begin(); it != vecT.end(); ++it)
{
int v_a = (*it)->a;//必须用(*it)获取到指针,然后访问到a
int v_b = (*it)->b;
} return ;
}

vector it->和*it的更多相关文章

  1. c++ vector 使用

    1. 包含一个头文件: 1 #include <vector> 2. 申明及初始化: std::vector<int> first; // empty vector of in ...

  2. Vector Tile

    Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...

  3. ArrayList、Vector、LinkedList的区别联系?

    1.ArrayList.Vector.LinkedList类都是java.util包中,均为可伸缩数组. 2.ArrayList和Vector底层都是数组实现的,所以,索引数据快,删除.插入数据慢. ...

  4. ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量

    当底层实现涉及到扩容时,容器或重新分配一段更大的连续内存(如果是离散分配则不需要重新分配,离散分配都是插入新元素时动态分配内存),要将容器原来的数据全部复制到新的内存上,这无疑使效率大大降低. 加载因 ...

  5. Java中Vector和ArrayList的区别

    首先看这两类都实现List接口,而List接口一共有三个实现类,分别是ArrayList.Vector和LinkedList.List用于存放多个元素,能够维护元素的次序,并且允许元素的重复.3个具体 ...

  6. C++使用vector

    #include <iostream> #include <string> #include <vector> using namespace std; void ...

  7. [LeetCode] Flatten 2D Vector 压平二维向量

    Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

  8. C++ 数组array与vector的比较

    转:http://blog.csdn.net/yukin_xue/article/details/7391897 1. array 定义的时候必须定义数组的元素个数;而vector 不需要: 且只能包 ...

  9. vector定义初始化

    头文件 #include<vector> using std::vector; vector<T> v1; vector<T> v2(v1); vector< ...

  10. vector迭代器用法

    #include<iostream> #include<vector> using namespace std; int main() { vector<int> ...

随机推荐

  1. Android Support 包知识

    Android Support Library包是一组代码库, 它提供了向后版本的framework API的兼容, 这些代码库实现的效果和只能在指定版本中使用的API一样好. 每个Support L ...

  2. ALM损坏后的恢复步骤

    ALM是HP出品的软件开发生命周期软件,其全称是Application Lifecycle Management,其采用B/S结构,从需求,业务模型到测试用例和缺陷管理亦应具有,满足了一般软件企业对开 ...

  3. (八)map,filter,flatMap算子-Java&Python版Spark

    map,filter,flatMap算子 视频教程: 1.优酷 2.YouTube 1.map map是将源JavaRDD的一个一个元素的传入call方法,并经过算法后一个一个的返回从而生成一个新的J ...

  4. MySQL高可用方案

    高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.虽然互联网服务号称7*24小时不间断服务,但多多少少有一些时候服务不可用,比如某些时候网页打不开,百度不能搜索或者无法 ...

  5. nth-of-type在选择class的时候需要注意的一个小问题

    查了下w3和MDN的手册,没发现有这个说明,写篇随笔记下. 1..class:nth-of-type(n)在选择class的时候,如果在class前面插入x个同类型标签,n需要加上x <!DOC ...

  6. JavaMail和James

      JavaMail,顾名思义,提供给开发者处理电子邮件相关的编程接口.它是Sun发布的用来处理email的API.它可以方便地执行一些常用的邮件传输.我们可以基于JavaMail开发出类似于Micr ...

  7. Oracle 获取当前日期及日期格式

    http://blog.sina.com.cn/s/blog_6168ee920100l2ye.html Oracle 获取当前日期及日期格式 获取系统日期:  SYSDATE()   格式化日期:  ...

  8. Django基础之wsgi

    Django 一 什么是web框架 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单地说,就是你用别人搭建好的舞台来做表演 ...

  9. codevs 2879 堆的判断

    codevs 2879 堆的判断 http://codevs.cn/problem/2879/ 题目描述 Description 堆是一种常用的数据结构.二叉堆是一个特殊的二叉树,他的父亲节点比两个儿 ...

  10. [LeetCode] Add Strings 字符串相加

    Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...