初识STL vector

时间:2024-12-13 18:03:44

写这个主要是当作笔记来写的,配上自己的理解加上一些测试示例;

上代码:

#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
#include<algorithm>
#define g 10000
using namespace std;
struct nood
  {
    int a;
    int b;
    char c;
  };
int main()
  {
    /**/
    vector<int> a,b;

    for(int i=0; i<10; i++)
    a.push_back(i);
    for(int i=0; i<10; i++)
      cout<<a[i]<<" ";
      for(int i=0; i<=10; i++)
      b.push_back(i);
    cout<<endl<<endl;
    for(int i=0; i<=10; i++)
      cout<<b[i]<<" ";
    cout<<endl<<"a=b? :"<<(a==b)<<" "<<endl<<endl;
    /**/
    nood xx;
    vector<struct nood> x,y;
    xx.a=100;
    xx.b=200;
    xx.c='B';
    x.push_back(xx);
    cout<<"xx.a=x[0].a? :"<<(xx.a==x[0].a)<<endl<<endl;
    /**/
    vector<string> d;
    vector<char> c;
    string dd;
    char cc='a';
    dd="asdasda~~";
    d.push_back(dd);
    d.push_back(dd);
    c.push_back(cc);
    cout<<d[0]<<" "<<d[1]<<endl;
    cout<<"d[0]=d[1]? :"<<(d[0]==d[1])<<endl
        <<"d[0]!=d[1] :"<<(d[0]!=d[1])<<endl;
    cout<<endl<<c[0]<<endl;
    /**/
    vector<vector<int> > aaa;
    aaa.push_back(a);
    aaa.push_back(b);
    for(int i=0;i<20;i++)
    cout<<aaa[i][i]<<endl;
    return 0;
  }

还有一些常用的删减查找过几天写 嘻嘻~~.

现在混个时间吗!!

好强发现了宝贝

#include <iomanip>

https://baike.baidu.com/item/iomanip/3319954?fr=aladdin.html