标签:The iostream replace string com pre rgb reverse 开始
#include <iostream> #include <vector> #include <string> #include <deque> #include <list> #include <forward_list> #include <array> //vector容器 vector<int> nums; nums.push_back(4); nums.pop_back(); nums.insert(nums.begin()+1,2); nums.size(); nums.empty(); nums.back(); //取最后一个元素 nums.earse(nums.begin()+1); //string容器 string s1 = ‘abc‘; string sub1 = s1.substr(0,5); s1.replace(6,5,‘game‘); //从位置6开始替换5个字符为‘game‘ s1.append(‘hello‘); s1.find(‘hello‘); s1.compare(string s2);//比较大小 //deque容器 deque<int> d1; d1.push_back(1); d1.pop_back(); d1.push_front(4); d1.pop_front(); d1.front(); d1.back(); //list容器 list<int> l1; l1.push_back(1); l1.pop_back(); l1.push_front(1); l1.pop_front(); l1.front(); l1.back(); l1.insert(l1.begin(),1);//某位置插入元素 l1.remove(2); l1.reverse(); l1.earse(--l1.end()); //array容器 array<int,3> myarr = {1,2,3}; array<array<int,3>,2> myarr2d = {1,2,3,4,5,6}; myarr.swap(myarr_other);//交换两个数组元素 myarr.assign(0); //把arr的元素全部置0 //遍历数组 for(int i = 0; i < myarr.size(); ++i){ cout << myarr[i] << endl; }
c++容器总结(vector、string、deque、list、array)
标签:The iostream replace string com pre rgb reverse 开始
原文地址:https://www.cnblogs.com/ywheunji/p/14028477.html