首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏iOS打包,上架知识大全

    c++stl

    C++ STL 教程 在前面的章节中,我们已经学习了 C++ 模板的概念。 extended vector size = 5 value of vec [0] = 0 value of vec [1] = 1 value of vec [2] = 2 value of vec [3] = 3 value of vec [4] = 4 value of v = 0 value of v = 1 value of v = 2 value of v = 3 value of v = 4

    71820编辑于 2023-03-21
  • 来自专栏iOS开发大全

    c++stl

    C++ STL 教程在前面的章节中,我们已经学习了 C++ 模板的概念。 0extended vector size = 5value of vec [0] = 0value of vec [1] = 1value of vec [2] = 2value of vec [3] = 3value of vec [4] = 4value of v = 0value of v = 1value of v = 2value of v = 3value of v = 4关于上面实例中所使用的各种函数

    73710编辑于 2023-01-18
  • 来自专栏C++与Linux的学习之路

    C++STL——哈希

    - begin3 << endl; cout << "set:" << end4 - begin4 << endl; } 把数组里面的数再多加一点,变成一百万。 但是这里就会有新问题,123%10=3,与数组里面的3相同,那么3的位置应该放哪一个? 这里就叫做哈希冲突,不同的值映射到相同的位置。 这里123%10等于3,但是下标为3的位置已经被占用了,所以只能向后找位置,发现下标为4的位置没有被占用,后续的1234插入的时候发现下标为4的位置被占用了,就向后找没被占用位置的位置。 其他哈希函数 平方取中法 假设关键字为1234,对它平方就是1522756,抽取中间的3位227作为哈希地址; 再比如关键字为4321,对它平方就是18671041,抽取中间的3位671(或710) = HashFunc3()(key) % (5 * N); if (!

    732120编辑于 2023-06-14
  • 来自专栏C++核心编程

    C++STL容器deque

    push_back(i); } printDeque(d1); deque<int> d2(d1.begin(),d1.end()); printDeque(d2); deque<int>d3( 10,100); printDeque(d3); deque<int>d4 = d3; printDeque(d4); } int main() { test01(); system( ) { d1.push_back(i); } printDeque(d1); deque<int>d2; d2 = d1; printDeque(d2); deque<int>d3; d3.assign(d1.begin(), d1.end()); printDeque(d3); deque<int>d4; d4.assign(10, 100); printDeque( d.begin(), 2,10000); printDeque(d); deque<int>d2; d2.push_back(1); d2.push_back(2); d2.push_back(3)

    59020编辑于 2022-09-28
  • 来自专栏编程碎碎念

    C++STL之 tuple

    a; double c; std:tie(a,ingore,c) = tup; std::cout<<"a="<<a<<" "<<"c="<<c<<endl; 程序的输出结果为a=l c=2.33 <em>3</em>. 用于连接tuple std::tuple<float, string> tup1(3.14, "pi"); std::tuple<int, char> tup2(10, 'a'); auto tup3 get<0>(tup); 输入第一个元素666. 2.tuple_element 获取tuple中特定元素数据结构 std::tuple_element<0, decltype(tup1)>::type 3.

    52720编辑于 2022-06-23
  • 来自专栏C++核心编程

    C++STL容器stack

    概念:stack是一种先进后出(First In Last Out,FILO)的数据结构,它只有一个出口

    38840编辑于 2022-09-29
  • 来自专栏全栈程序员必看

    C++STL容器总结

    2.创建vecotr对象: (1) vector<int> v1; (2) vector<int> v2(10); 3.基本操作: v.capacity(); //容器容量 v.size 创建deque对象 (1) deque<int> d1; (2) deque<int> d2(10); 3. }; set<int> a(b,b+5); set<int>::iterator it; it=a.find(3); if(it! (3) map内部自建了一颗红黑二叉树,可以对数据进行自动排序,所以map里的数据都是有序的,这也是我们通过map简化代码的原因。 创建对象: map<T1,T2> m; map<T1,T2, op> m; //op为排序规则,默认规则是less<T> 3.

    1.4K10编辑于 2022-07-21
  • C++STL之queue

    3. 底层容器可以是标准容器类模板之一,也可以是其他专门设计的容器类。 否则返回false size() 返回队列中有效元素的个数 front() 返回队头元素的引用 back() 返回队尾元素的引用 push() 在队尾将元素val入队列 pop() 将队头元素出队列 3.

    11510编辑于 2025-12-30
  • 来自专栏C++核心编程

    C++STL容器vector

    push_back(i); } printVector(v1); vector<int> v2(v1.begin(), v1.end()); printVector(v2); vector<int> v3( 10, 100); printVector(v3); vector<int> v4(v3); printVector(v4); } int main() { test01(); system v1.push_back(i); } printVector(v1); vector<int>v2; v2 = v1; printVector(v2); vector<int>v3; v3.assign(v1.begin(), v1.end()); printVector(v3); vector<int>v4; v4.assign(10, 100); printVector ); } cout << "v的容量为:" << v.capacity() << endl; cout << "v的大小为:" << v.size() << endl; v.resize(3)

    40710编辑于 2022-09-28
  • 来自专栏C++核心编程

    C++STL容器string

    "hello world"; string s2(str); //把c_string转换成了string cout << "str2 = " << s2 << endl; string s<em>3</em>( s2); //调用拷贝构造函数 cout << "str3 = " << s3 << endl; string s4(10, 'a'); cout << "str3 = " << s3 << endl str3 = 'a'; cout << "str3 = " << str3 << endl; string str4; str4.assign("hello c++"); cout << = "I"; str3.append(" love "); str3.append("game abcde", 4); //str3.append(str2); str3.append(str2 , 4, 3); // 从下标4位置开始 ,截取3个字符,拼接到字符串末尾 cout << "str3 = " << str3 << endl; } int main() { test01();

    40740编辑于 2022-09-26
  • 来自专栏软件开发 -- 分享 互助 成长

    C++STL 之排列

    所以如果是生成一个数组的全排列,先要对数组按升序排序,然后使用do-while语句循环调用next_permutation函数 1 #include<iostream> 2 #include<algorithm> 3 1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 using namespace std; 5 int main()

    88570发布于 2018-02-05
  • C++STL之vector

    3. 注意:Linux下,g++编译器对迭代器失效的检测并不是非常严格,处理也没有vs下极端。 // 1. 扩容之后,vector的容量为: 100 0 2 3 4 5 409 1 2 3 4 5 // 2. erase删除任意位置代码后,linux下迭代器并没有失效 // 因为空间还是原来的空间,后序元素往前搬移了 ,删除之后it已经超过end // 此时迭代器是无效的,++it导致程序崩溃 int main() { vector<int> v{1,2,3,4,5}; // vector<int> v{1,2,3,4,5,6 3-centos 20220114]$ vim testVector.cpp [sly@VM-0-3-centos 20220114]$ g++ testVector.cpp -std=c++11 [sly @VM-0-3-centos 20220114]$ .

    21610编辑于 2025-12-30
  • C++STL之stack

    9410编辑于 2025-12-30
  • C++STL之string

    namespace std; int func1() { return 10; } // 不能做参数 void func2(auto a) {} 比特就业课 // 可以做返回值,但是建议谨慎使用 auto func3( ) { return 3; } int main() { int a = 10; auto b = a; auto c = 'a'; auto d = func1(); // 编译报错:rror C3531 <iostream> #include <string> #include <map> using namespace std; int main() { int array[] = { 1, 2, 3, 3. resize(size_t n) 与 resize(size_t n, char c)都是将字符串中有效字符个数改变到n个,不 同的是当字符个数增多时:resize(n)用0来填充多出的元素空间 4. reserve(size_t res_arg=0):为string预留空间,不改变有效元素个数,当reserve的参 数小于string的底层空间总大小时,reserver不会改变容量大小 3.

    16810编辑于 2025-12-30
  • C++STL之list

    rbegin(end) 与 rend(begin) 为反向迭代器,对迭代器执行 ++ 操作,迭代器向前移动 3.list的常用接口 函数声明 接口说明 empty 检测 list void TestListIterator1() { int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; list<int> l(array, array+sizeof it无效,在下一次使用it时,必须先给 其赋值 l.erase(it); ++it; } } // 改正 void TestListIterator() { int array[] = { 1, 2, 3, size; }; void test_list1() { list<int> lt; lt.push_back(1); lt.push_back(2); lt.push_back(3)

    11710编辑于 2025-12-30
  • 来自专栏Golang开发

    C++STL常用算法

    vector<int> vecInt; vecInt.push_back(1); vecInt.push_back(2); vecInt.push_back(3); vecInt.push_back vector<int> vecInt; vecInt.push_back(3); vecInt.push_back(3); vecInt.push_back(1); vecInt.push_back vector<int> vecInt; vecInt.push_back(3); vecInt.push_back(3); vecInt.push_back(2); vecInt.push_back ; set<int>::iterator it1 = mypair.first; cout << "it1:" << *it1 << endl; //3 //4 set<int 例如:vecIntA,vecIntB,vecIntC是用vector<int>声明的容器,vecIntA已包含1,3,5,7,9元素,vecIntB已包含2,4,6,8元素 vecIntC.resize

    61630发布于 2019-05-28
  • C++STL】map multimap 保姆级教程:从底层原理到实战应用!

    右边"},{"sort","排序"} }; //拷贝构造 map<string, string> dict2(dict1); //迭代器区间构造 map<string, string> dict3( 插入数据 map的插入接口主要掌握以下几个接口: 代码示例: #include<iostream> #include<map> using namespace std; void test_map3( "sort", "排序"); pair<string, string> kv4("const", "常量"); map<string, string> dict = { kv1,kv2,kv3,kv4 (); dict.insert(pos,{"English","英文"}); vector<pair<string,string>> v={{"k1","v1"},{"k2","v2"},{"k3" ,"v3"}}; //迭代器区间插入 dict.insert(v.begin(),v.end()); for(const auto& e:dict ) { cout<<e.first<<

    37210编辑于 2025-12-23
  • C++STL】set multiset 保姆级教程:从底层原理到实战应用!

    };//中序遍历 加上排序去重 //隐式类型转化 set<int> s2({1, 2, 3, 2, 5, 6, 7,9,10,8,12}); //拷贝构造 set<int> s3(s); / };//中序遍历 加上排序去重 //隐式类型转化 set<int> s2({1, 2, 3, 2, 5, 6, 7,9,10,8,12}); //拷贝构造 set<int> s3(s); ) { set<int> s = { 1,3,4,6,2,1,5,9,7,8 };//中序遍历 加上排序去重 //删除 auto pos=s.find(9); if(pos! 3、lower_bound和upper_bound的使用 lower_bound 返回指向第一个不小于给定值的元素的迭代器。如果所有元素都小于给定值,则返回 end()。 ) { //multi_set不需要另外包含头文件 已经被set包含 //multi_set与set最大的区别就是multi_set支持重复数据 multiset<int> s = { 1,2,3,3,5,3,7,9,10,40,3

    50010编辑于 2025-12-23
  • 来自专栏C++与Linux的学习之路

    C++STL——stack与queue

    iostream> #include<stack> #include<queue> int main() { stack<int> a; a.push(1); a.push(2); a.push(3) main() { priority_queue<int> a;//大堆 priority_queue<int, vector<int>, greater<int>> b;//小堆 a.push(3) a.empty()) { cout << a.top() << ' '; a.pop(); } cout << endl; b.push(3); b.push(0); b.push(

    41200编辑于 2023-03-28
  • 来自专栏数据分析与挖掘

    c++STL容器之setmultiset容器

    3.set中不允许有重复的元素,multiset里面允许有重复的元素。 Person, comparePerson>s; //创建Person对象 Person p1("刘备", 24); Person p2("关羽", 28); Person p3( "张飞", 25); Person p4("赵云", 21); s.insert(p1); s.insert(p2); s.insert(p3); s.insert

    49620发布于 2020-08-26
领券