#include <iostream>#include<string>#include<vector>#include<queue>usingnamespacestd;intmain(intargc,constchar*argv[]) { queue<int>q;q.push(12);q.push(23); q.push(4); q.push(5); q.push(7);while(!q.empty()) { cout<<q.front()<<endl;q.pop();}return0; }/*输出: 12 23 4...
deque.pop_front(); //删除容器第一个数据 deque<int>deqInt;deqInt.push_back(1);deqInt.push_back(3);deqInt.push_back(5);deqInt.push_back(7);deqInt.push_back(9);deqInt.pop_front();deqInt.pop_front();deqInt.push_front(11);deqInt.push_front(13);deqInt.pop_back();deqInt.pop_...
auto i= find_if (myvector.begin(),myvector.end(),[](int v){return v>4;}); //如果找到myvector 中第一个大于四的数据则返回那个数据所在位置的迭代器,否则返回myvector.end(); auto i= find_if_not (myvector.begin(),myvector.end(),[](int v){return v>4;}); //如果找到myvector 中...
vector, 变长数组,倍增的思想 size() 返回元素个数 empty() 返回是否为空 clear() 清空 front()/back() push_back()/pop_back() begin()/end() [] 支持比较运算,按字典序pair<int, int> first, 第一个元素 second, 第二个元素 支持比较运算,以first为第一关键字,以second为第二关键字(字典序)stri...
push_back、emplace_backvector 更改容量时全部失效。否则只有end()。 insert、emplacevector 更改容量时全部失效。否则只有在或于插入点后者(包括end())。 resizevector 更改容量时全部失效。否则只有end()与被擦除元素。 pop_back被擦除元素和end()。
vectorname.push_back(value)Parameters :The value to be added in the back is passed as the parameterResult :Adds the value mentioned as the parameter to the back of the vector named asvectorname Examples: Input : myvector = {1, 2, 3, 4, 5}; ...
voidpush_front(constT&value); (1)(since C++11) voidpush_front(T&&value); (2)(since C++11) Prepends the given elementvalueto the beginning of the container. No iterators or references are invalidated. Parameters Return value (none)
#include <iostream>#include <vector>intmain(){// Create a vector containing integersstd::vector<int>v={8,4,5,9};// Add two more integers to vectorv.push_back(6);v.push_back(9);// Overwrite element at position 2v[2]=-1;// Print out the vectorfor(intn:v)std::cout<<n<<'...
类模板 std::vectornamespace std { template<class T, class Allocator = allocator<T>> class vector { public: // 类型 using value_type = T; using allocator_type = Allocator; using pointer = typename allocator_traits<Allocator>::pointer; using const_pointer = typename allocator_traits<Allocator...
vector::size vector::max_size vector::reserve vector::capacity vector::shrink_to_fit (DR*) Modifiers vector::clear vector::insert vector::emplace (C++11) vector::insert_range (C++23) vector::erase vector::push_back vector::emplace_back ...