当前位置:网站首页>STL container
STL container
2022-07-05 01:50:00 【Porter hunter of the program】
A rough summary
stl Containers
cin>>s; Space , enter ,EOF end
getline(cin,s); The input line , The space does not end
length s.size();
Traverse :
for(int i=0;i<s.size();i++){
cout<<s[i];
}
Splicing :string t=”123”;
string s=”456”;
s=s+t;//s=”123456”;
s=s+”789”;//s=”123456789”;
s=”00”+s;//s=”00123456789”
Empty :s.clear();
s.empty();// If s If it is empty, the value is 1, Otherwise 0;
vector
One dimensional operation :
Definition :vector<int>v;Insert :v.push_back(1);
cout<<v[0];
Two dimensional operation :
vector< vector<int> > asd1;// Definition
For a one-dimensional array , have access to size() Get its length .
int size = asd.size();
For two dimensional arrays , You can use the following methods to get rows 、 Column length .
int size_row = asd1.size(); // Get the number of lines
int size_column = asd1[0].size(); // Get the number of columns
Direct assignment
asd1[1][1] = 1;
cout << asd1[1][1] <<endl;
asd1[1].push_back(23); // Insert column elements
asd1.push_back(asd); // Insert a row
Delete row :
auto test1 = asd1.begin();
asd1.erase(++test1);
Delete column :
auto test2 = test1.begin();
asd1[0].erase(++test2);
Traverse :
vector<vector<int> >::iterator p1;
vector<int>::iterator p2;
for (p1 = a.begin(); p1 != a.end(); p1++){
for (p2 = p1->begin(); p2 != p1->end(); p2++){
cout << "[" << *p2 << "]";
}
}
stack
stack<int>st;
First in, then out
Input :
st.push(1);// Add
Output :
st.top();// Output the first element of the stack
st.pop();// Delete the first element of the stack
Redefinition will automatically clear
while(cin>>n) stack<int>st;
queue
queue<int>q;
fifo
Input :
q.push(1);Output :
q.front();
q.pop();Priority queue
priority_queue<int>q;// Big root pile , null
Input :
q.push(1);Output :
q.top();
q.pop();priority_queue<int,vector<int>,greater<int>>tp;// Heap , Ascending sort
set To reorder
set<int>st;
st.insert();
*st.begin();// First element *st.end(); The last element
st.find(1);// Find out if there is 1 This element ;
st.count(1);// There are several elements 1;
multiset<int>st;// Don't reorder ;
map Array
map<int,string>mp;//int It's equivalent to a subscript ,string Equivalent to content
int and string The type of can be changed at will ;
mp[1]=”123”;
deque deque
deque<int>d;
iterator :
begin() Point to the position of the first element
end() Point to the position after the last element
rbegin() Point to a position before the first element
rend() Point to the last element position
Capacity dependent :
size() Returns the size of the container
max_size() Returns the maximum capacity of the container
empty() Judge whether the container is empty
resize() Change the size of the container
Member visit :
Use [ ] Access to , Use .at() Access to
front() Returns the first element
back() Return to the last element
Container adjustment :
assign Reassign elements to containers
push_back Insert the element... At the end of the container
push_front Insert the element... At the beginning of the element
pop_back Delete last element
pop_front Delete the beginning element
insert Inserts an element into the specified position , The return value is the iterator pointing to the last insertion position
erase Remove elements
swap Swap two containers
clear Empty the container
emplace Inserts an element into the specified position , Only a single element can be inserted
emplace_front Insert the element at the beginning of the container ( Efficient than push_front high )
emplace_back Insert the element at the end of the container
边栏推荐
- [Chongqing Guangdong education] National Open University spring 2019 1042 international economic law reference questions
- batchnorm.py这个文件单GPU运行报错解决
- Using openpyxl module to write the binary list into excel file
- Go RPC call
- The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
- runc hang 导致 Kubernetes 节点 NotReady
- Luo Gu Pardon prisoners of war
- Win: use shadow mode to view the Desktop Session of a remote user
- Rabbit MQ message sending of vertx
- The server time zone value ‘� й ��� ʱ 'is unrecognized or representatives more than one time zone【
猜你喜欢

How to build a technical team that will bring down the company?

Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and mobile phones can also easily read literature

Nebula Importer 数据导入实践

Interesting practice of robot programming 15- autoavoidobstacles

MySQL regexp: Regular Expression Query

微信小程序:独立后台带分销功能月老办事处交友盲盒
![[Digital IC hand tearing code] Verilog edge detection circuit (rising edge, falling edge, double edge) | topic | principle | design | simulation](/img/9e/4c8557bb4b75b1e74598dedb24af86.jpg)
[Digital IC hand tearing code] Verilog edge detection circuit (rising edge, falling edge, double edge) | topic | principle | design | simulation

Incremental backup? db full

phpstrom设置函数注释说明

Interesting practice of robot programming 14 robot 3D simulation (gazebo+turtlebot3)
随机推荐
Win: use PowerShell to check the strength of wireless signal
PowerShell:在代理服务器后面使用 PowerShell
【LeetCode】88. Merge two ordered arrays
Security level
微信小程序;胡言乱语生成器
One click generation and conversion of markdown directory to word format
Process scheduling and termination
How to build a technical team that will bring down the company?
Outlook: always prompt for user password
MySQL REGEXP:正则表达式查询
MySQL regexp: Regular Expression Query
Win:使用 PowerShell 检查无线信号的强弱
phpstrom设置函数注释说明
Wechat applet: wechat applet source code download new community system optimized version support agent member system function super high income
[Digital IC hand tearing code] Verilog edge detection circuit (rising edge, falling edge, double edge) | topic | principle | design | simulation
Binary tree traversal - middle order traversal (golang)
Collection of gmat750 wrong questions
PowerShell: use PowerShell behind the proxy server
Matrixone 0.2.0 is released, and the fastest SQL computing engine is coming
es使用collapseBuilder去重和只返回某个字段