美文网首页
c++ 常用STL整理

c++ 常用STL整理

作者: 若昭 | 来源:发表于2019-07-05 11:58 被阅读0次

最近在练习C++编程,做了一些牛客和力扣上面的题目,发现常用的C++ STL 有以下几种,对此进行简要总结,以便自己及时复习。

文章大多来自转载,感谢社区程序员的共享。

C++ 中常用的STL 有:

  1. algorithm:
    #include<algorithm>
algorithm 在STL中的应用主要是: sort()   swap()   reverse()   find()
max(), min(), abs()
swap()
reverse()  //reverse(vi.begin(), vi.end());
sort()     // sort(a, a+4);
find()     // find(vi.begin(), vi.end(), 3);
next_permutation()    // could get all sequence for several numbers. 000_algorithm.cpp
fill()     // fill(a, a+5, 233);
*min_element(num,num+6)
*max_element(num,num+6)
lower_bound和upper_bound()

https://blog.csdn.net/weixin_40349531/article/details/88361095

  1. math:
    #include<cmath>
    // #include<math.h>

https://blog.csdn.net/zy2317878/article/details/79414431
https://blog.csdn.net/FX677588/article/details/52962798

  1. vector:
    #include<vector>
push_back();
pop_back();
begin();
end();
insert();
erase();
find();
at();
size();

http://blog.chinaunix.net/uid-26000296-id-3785623.html
http://blog.chinaunix.net/uid-26000296-id-3785610.html
https://www.cnblogs.com/aminxu/p/4686332.html

  1. string:
    #include<string>
data();       // 返回指向自己的第一个字符的指针
+=            // 连接操作符
append();
insert();
find();       // if not include, return iterator::end()
replace();
size();
substr();
swap();

http://blog.chinaunix.net/uid-26000296-id-3781405.html
https://www.cnblogs.com/aminxu/p/4686320.html#at

  1. set:
    #include<set>
// set的特性是,所有元素都会根据元素的键值自动排序.
// set的元素不像map那样可以同时拥有实值(value)和键值(key),set元素的键值就是实值,实值就是键值。
// set不允许两个元素有相同的键值.

https://www.cnblogs.com/omelet/p/6627667.html

  1. map:
    #include<map>
// map的特性是,所有元素都会根据元素的键值自动被排序。
// map的所有元素都是pair,同时拥有实值(value)和键值(key)。
// pair的第一个元素会被视为键值,第二个元素会被视为实值。
// map不允许两个元素拥有相同的键值。

map<string , int> strMap;    // constructor
strMap.insert(map<string, int>::value_type("a", 1));
strMap["a"] = 1;             // for insert, will override 覆盖之前的值
size();

https://www.cnblogs.com/omelet/p/6617362.html
https://blog.csdn.net/sevenjoin/article/details/81943864

  1. others:
    7.1 int <--> string
#include <iostream>
#include <string>
#include <sstream>
#include <stdlib.h>
using namespace std;
int main()
{
    // int 转 string
    stringstream ss;
    int n = 123;
    string str;
    ss<<n;
    ss>>str;
    cout << str << endl;
    // string 转 int
    str = "456";
    n = atoi(str.c_str());
    cout << n << endl;

    return 0;
}

7.2 int number <--> char

char ch = '2';
int in = ch - '0';
in = in + 1;
char chHigher = in + '0';

7.3 random number:

#include <stdlib.h>
#include <iostream>
#include <time.h>
#define MAX 100
using namespace std;
int  main()
{
    srand( (unsigned)time(NULL) );
    for(int i=0; i<10; i++)
        cout<<rand()%MAX<<endl;

    return 0;
}

https://www.jb51.net/article/124108.htm

相关文章

  • c++ 常用STL整理

    最近在练习C++编程,做了一些牛客和力扣上面的题目,发现常用的C++ STL 有以下几种,对此进行简要总结,以便自...

  • 1. 入门并实践STL——vector篇

    此笔记整理自《算法笔记》电子版下载 密码:yhpimb其他资料:STL教程:C++ STL快速入门(非常详细) 1...

  • 读书笔记17.06.03

    C++ STL:Listlist是C++标准模版库(STL,Standard Template Library)中...

  • [C++] STL 容器

    参考:[C++] STL 容器 (一) - 基本介紹[C++] STL 容器 (二) - Iterator 部分示例:

  • 第二章 C++ STL 泛型编程 1

    一、STL 概述 STL——C++标准模板库,定义了常用的数据结构和算法。提供三种类型的组件:容器、迭代器和算法。...

  • C++STL整理

    C++ STL中最基本以及最常用的类或容器string、vector、set、list、map string 处理...

  • C++后端开发的踩坑整理

    C++开发的一些经验和踩坑整理 STL相关的坑 1. std::sort()函数要求严格弱序 STL文档中要求so...

  • C++ STL 学习笔记

    C++ STL 学习笔记

  • STL之参考文献

    C++标准库是离不开模板的,STL占了C++标准库80%以上。 学习STL(c++ 98)的主要参考: gcc 3...

  • c++常用的STL

    c++ 中常用的内置函数 标签: c++ 1. algorithm中处理数组/vect的函数 1.可以处理两种数据...

网友评论

      本文标题:c++ 常用STL整理

      本文链接:https://www.haomeiwen.com/subject/tbmshctx.html