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

    c++stl

    C++ STL 教程 在前面的章节中,我们已经学习了 C++ 模板的概念。 vec; int i; // 显示 vec 的原始大小 cout << "vector size = " << vec.size() << endl; // 推入 <em>5</em> 个值到向量中 for(i = 0; i < <em>5</em>; i++){ vec.push_back(i); } // 显示 vec 扩展后的大小 cout << "extended vector size = " << vec.size() << endl; // 访问向量中的 <em>5</em> 个值 for(i = 0; i < <em>5</em>; i++){ cout << endl; v++; } return 0; } 当上面的代码被编译和执行时,它会产生下列结果: vector size = 0 extended vector size = <em>5</em>

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

    c++stl

    C++ STL 教程在前面的章节中,我们已经学习了 C++ 模板的概念。 vector<int> vec; int i; // 显示 vec 的原始大小 cout << "vector size = " << vec.size() << endl; // 推入 <em>5</em> 个值到向量中 for(i = 0; i < <em>5</em>; i++){ vec.push_back(i); } // 显示 vec 扩展后的大小 cout << "extended vector size = " << vec.size() << endl; // 访问向量中的 <em>5</em> 个值 for(i = 0; i < <em>5</em>; i++){ cout << "value of vec *v << endl; v++; } return 0;}当上面的代码被编译和执行时,它会产生下列结果:vector size = 0extended vector size = 5value

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

    C++STL——哈希

    "unordered_set:" << end3 - begin3 << endl; cout << "set:" << end4 - begin4 << endl; size_t begin5 = clock(); for (auto e : arr) { arr1.erase(e); } size_t end5 = clock(); size_t begin6 = clock( - begin5 << endl; cout << "set:" << end6 - begin6 << endl; } 如果是有序的话,set会更快。 * N));//将key分别映射到三个位置 arr.set(HashFunc2()(key) % (5 * N)); arr.set(HashFunc3()(key) % (5 * N)); ()(key) % (5 * N); size_t hashi3 = HashFunc3()(key) % (5 * N); if (!

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

    C++STL容器deque

    cout << "d1的大小为:" << d1.size() << endl; } //重新指定大小 d1.resize(15, 1); printDeque(d1); d1.resize(5)

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

    C++STL之 tuple

    c++中的tuple是一个允许存放多种不同的数据类型的容器,是针对pair的泛型,和pair一样在std 的namespace中,在使用的时候,需要引用头文件,同时注意namespace;

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

    C++STL容器stack

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

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

    C++STL容器总结

    rit<<endl; find(key_value);//如果找到查找的键值,则返回该键值的迭代器位置,否则返回集合最后一个元素后一个位置的迭代器,即end(); 如:int b[]={1,2,3,4,5} ; set<int> a(b,b+5); set<int>::iterator it; it=a.find(3); if(it! 其中,m表示断号ID,n表示重号ID 样例输入: 2 5 6 8 11 9 10 12 9 样例输出: 7 9 五、map/multimap 去重类问题 可以打乱重新排列的问题 有清晰的一对一关系的问题 (5) key和value一一对应的关系可以去重。 2. 创建对象: map<T1,T2> m; map<T1,T2, op> m; //op为排序规则,默认规则是less<T> 3.

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

    1. 队列是一种容器适配器,专门用于在FIFO上下文(先进先出)中操作,其中从容器一端插入元

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

    C++STL容器vector

    ,可以利用重载版本替换默认填充 v1.resize(15,10); printVector(v1); //resize 重新指定大小 ,若指定的更小,超出部分元素被删除 v1.resize(5)

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

    C++STL容器string

    << endl; string str4; str4.assign("hello c++"); cout << "str4 = " << str4 << endl; string str<em>5</em>; str<em>5</em>.assign("hello c++",5); cout << "str5 = " << str5 << endl; string str6; str6.assign(str5); cout << "str6 = " << str6 << endl; string str7; str7.assign(<em>5</em>, 'x'); cout << "str7 = " << str7

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

    C++STL 之排列

    next_permutation函数 1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 using namespace std; 5 1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 using namespace std; 5 int main()

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

    vector的成员接口) insert 在position之前插入val erase 删除position位置的数据 swap 交换两个vector的数据空间 operator[] 像数组一样访问 5. = v.end()) { cout << *it << " "; ++it; } cout << endl; return 0; } 程序输出: 1 2 3 4 5 扩容之前,vector的容量为: 5 扩容之后,vector的容量为: 100 0 2 3 4 5 409 1 2 3 4 5 // 2. erase删除任意位置代码后,linux下迭代器并没有失效 // 因为空间还是原来的空间,后序元素往前搬移了 ,it的位置还是有效的 #include <vector> #include <algorithm> int main() { vector<int> v{1,2,3,4,5}; vector<int> ,删除之后it已经超过end // 此时迭代器是无效的,++it导致程序崩溃 int main() { vector<int> v{1,2,3,4,5}; // vector<int> v{1,2,3,4,5,6

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

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

    必须始终推导为同一类型 auto cc = 3, dd = 4.0; // 编译报错:error C3318: “auto []”: 数组不能具有其中包含“auto”的元素类型 auto array[] = { 4, 5, iostream> #include <string> #include <map> using namespace std; int main() { int array[] = { 1, 2, 3, 4, 5 5. string类非成员函数 函数名称 功能说明 operator+ 尽量少用,因为传值返回,导致深拷贝效率低 operator>> 输入运算符重载 operator<< 输出运算符重载 getline

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

    void TestListIterator1() { int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; list<int> l(array, array+sizeof 在下一次使用it时,必须先给 其赋值 l.erase(it); ++it; } } // 改正 void TestListIterator() { int array[] = { 1, 2, 3, 4, 5, = l.end()) { l.erase(it++); // it = l.erase(it); } } 5.list的模拟实现 #pragma once #include<iostream>

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

    C++STL常用算法

    1); vecInt.push_back(2); vecInt.push_back(3); vecInt.push_back(4); vecInt.push_back(5) ; vecInt.push_back(5); vector<int>::iterator it = adjacent_find(vecInt.begin(), vecInt.end()) set<int> setInt; setInt.insert(2); setInt.insert(1); setInt.insert(8); setInt.insert(5) 例如:vecIntA,vecIntB,vecIntC是用vector<int>声明的容器,vecIntA已包含1,3,5,7,9元素,vecIntB已包含2,4,6,8元素 vecIntC.resize str("itcastitcast "); random_shuffle(vecInt.begin(), vecInt.end()); //随机排序,结果比如:9,7,1,5,3

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

    代码示例: #include<iostream> #include<map> using namespace std; void test_map5() { map<int, string> m = { {1,"a"},{2,"b"},{3,"c"},{5,"e"},{4,"d"},{6,"f"}}; auto pos1 = m.lower_bound(2); auto pos2 = m.upper_bound

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

    using namespace std; void test_set1() { //使用initializer_list(初始化列表)构造 set<int> s = { 1,3,4,6,2,1,5,9,7,8 };//中序遍历 加上排序去重 //隐式类型转化 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); ; s.insert(2); s.insert(7); s.insert(5); auto it = s.begin(); while (it ! 代码示例: void test_set4() { set<int> s2({1, 2, 3, 2, 5, 6, 7,9,10,8,12}); //==========================

    50010编辑于 2025-12-23
  • 来自专栏波波烤鸭

    SpringMVC教程5

    在需要回传的对象前添加@ModelAttribute(“bb”)注解,在界面中就可以通过bb前缀来获取回写信息。

    1K20发布于 2019-04-02
  • 来自专栏C++与Linux的学习之路

    C++STL——stack与queue

    #include<queue> int main() { stack<int> a; a.push(1); a.push(2); a.push(3); a.push(4); a.push(5) priority_queue<int, vector<int>, greater<int>> b;//小堆 a.push(3); a.push(0); a.push(9); a.push(5) cout << a.top() << ' '; a.pop(); } cout << endl; b.push(3); b.push(0); b.push(9); b.push(5) const T& a, const T& b) { return a < b; } }; } int main() { int a = 4; int b = 0; int c = 5;

    41200编辑于 2023-03-28
领券