c++ vector struct 使用

1.

//test.h
#include <string>
using namespace  std;
struct AA
{
    string a1;
    string a2;
    string a3;
};

class test
{
public:
    void ReadString(vector<AA> vv);

};
#include "StdAfx.h"
#include "test.h"

void test::ReadString(vector<AA> vv)
{
    vector<AA>::iterator it;
    for (it=vv.begin();it!=vv.end();++it)
    {
        string ss=it->a1;
    }

}
void CtttttttDlg::OnBnClickedButton1()
{
    // TODO: Add your control notification handler code here

   AA aa1;
   aa1.a1="aaaa11";
   aa1.a2="aaaa12";
   aa1.a3="aaa13";

   AA aa2;
   aa2.a1="aaaa21";
   aa2.a2="aaaa22";
   aa2.a3="aaa23";

   vector<AA> vv;
   vv.push_back(aa1);
   vv.push_back(aa2);

   /*vector<AA>::iterator it;
   for (it=vv.begin();it!=vv.end();++it)
   {
       string ss=it->a1;
   }
  */

   test ts;
   ts.ReadString(vv);

}
时间: 2024-07-30 15:51:00

c++ vector struct 使用的相关文章

STL review:vector &amp; struct

I.vector 1.头文件:#include<vector>                        //容器vector是一个能实现随机存取.插入删除的动态数组,还可以当栈使. 2.创建: vector<int> v1:                             // < >里可以是struct或者vector嵌套:vector< vector<int> > ivec; vector是一个类模板,创建一个vector的过程

实战c++中的vector系列--creating vector of local structure、vector of structs initialization

之前一直没有使用过vector<struct>,现在就写一个简短的代码: #include <vector> #include <iostream> int main() { struct st { int a; }; std::vector<st> v; v.resize(4); for (std::vector<st>::size_type i = 0; i < v.size(); i++) { v.operator[](i).a =

用邻接表或vector实现存边以及具体如何调用[模板]

存边: 对于指针实现的邻接表: struct edge{ int from,next,to,w; }E[maxn]; int head[maxn],tot=0;//head初始化为-1: void add(int x,int y,int z){ E[++tot].from=x;//头结点 E[tot].to=y;//连接的下一个结点 E[tot].w=z;//边权值 E[tot].next=head[x];//连接指针 head[x]=tot;//指针指向tot,即可通过head[x]为下标,运

获取网络接口信息——ioctl()函数与结构体struct ifreq、 struct ifconf

转载请注明出处:windeal专栏 Linux 下 可以使用ioctl()函数 以及 结构体 struct ifreq  结构体struct ifconf来获取网络接口的各种信息. ioctl 首先看ioctl()用法 ioctl()原型如下: #include <sys/ioctl.h> int ioctl(int fd, int request, ...); 参数: fd     : 文件描述符 request:  表示要请求的信息.如IP地址.网络掩码等 ...     :  后面的可变

vector it-&gt;和*it

//每次写代码总是被迭代器的iter->和*iter弄晕,主要是被protobuf弄晕了 #include <vector> struct test{ test(){ memset(this, 0, sizeof(test)); } int a; int b; }; int main() { test a, b; a.a = a.b = 0; b.a = b.b = 1; //std::vector<test> vecT; //vecT.push_back(a); //vec

回归季——C++ STL vector

博主从几年前开始脱离ACM大军,至今已经三个年头,花了点时间改善了一下环境.最近回归程序猿大军,发现代码力一落千丈,早已不是以前一晚上横扫OJ的程序猿预备军了.现在已经沦为代码渣渣.至此从新开始写博客,从新巩固代码力.会陆续的把学习的过程更新出来,希望代码力早日恢复T_T. 最近刷LeetCode,才发现原来在刷ACM的时候,用大量的C代替了STL的做法在leetcode上实行起来并不方便,所以痛定思痛.从很久以前不想学的STL开始入手,早就听说STL是个好东西,只是习惯了写C,就懒得去学C++

二维vector容器读取txt坐标

template <class vector> struct HeadLocation{ vector x; vector y; }; vector<HeadLocation<int> > gt_loc_; //二维vector容器 void ReadLocationFromTextFile(const string filename) { cout << "Opening file " << filename <<

C++ STL(二)vector的用法

##### vector的定义 ```#include <iostream>#include <string>#include <vector>using namespace std;struct stu{ int age;};class xx{ string s;};void vectorDefine(){ vector<int> vec; vector<struct stu> vec2; vector<xx> vec3; vect

[LeetCode] 349 Intersection of Two Arrays &amp; 350 Intersection of Two Arrays II

这两道题都是求两个数组之间的重复元素,因此把它们放在一起. 原题地址: 349 Intersection of Two Arrays :https://leetcode.com/problems/intersection-of-two-arrays/description/ 350 Intersection of Two Arrays II:https://leetcode.com/problems/intersection-of-two-arrays-ii/description/ 题目&解法