STL(标准模板类库)简介

STL:标准模板类库

map:集合

vector:矢量(C++中叫做容器)

list:表

 

迭代器:广义指针

vector类的运用:

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    vector<int> x;//运用容器类的例子
    for(int a=0;a<1000;a++){
        x.push_back(a);
    }

    vector<int>::iterator p;
    for(p=x.begin();p<x.end();p++){
        cout<<*p<<endl;
    }
    return 0;
}

List类的运用:

#include <iostream>
#include <list>
#include <string>
using namespace std;

int main()
{
    list<string> s;
    s.push_back("hello");
    s.push_back("world");
    s.push_front("tide");
    s.push_front("crimson");
    s.push_front("alabama");

    list<string>::iterator p;
    for(p=s.begin();p!=s.end();p++){
        cout<<*p<<endl;
    }
    return 0;
}



猜你喜欢

转载自blog.csdn.net/hello_leiyuanyi/article/details/80593275