当前位置:网站首页>期末琐碎知识点再整理
期末琐碎知识点再整理
2022-07-01 14:36:00 【团团带你学代码】
- insert是对于map
- push_back是对于vector
- 使用insert时,还要使用make_pair(,)
- 假如使用pair,则要注明数据类型,假如使用make_pair则不用注明数据类型。
- 读取文件操作,while()括号中加上fstream后面的内容
- 注意在文件操作中,>>是读文件操作,<<是写文件操作,不要弄混了。(记忆方法可以这样理解:cin>>.... cout<<.... cin是输入,cout是输出。
第一种理解方式:
向文件中输出,故写文件对应cout<<
第二种理解方式:
和cin cout正好相反
)
7.find查找(仅限于map容器才能使用该函数)
8.map和multimap的特殊搜寻函数
操作 | 效果 |
count(key) | 返回”键值等于key”的元素个数 |
find(key) | 返回”键值等于key”的第一个元素,找不到返回end |
lower_bound(key) | 返回”键值大于等于key”的第一个元素 |
upper_bound(key) | 返回”键值大于key”的第一个元素 |
equal_range(key) | 返回”键值等于key”的元素区间 |
特别是lower_bound和upper_bound函数,以前关注的比较少,这次考试是必然会考的。
9.可以考虑使用set容器,利用其自动去重的特点。(不要忘记加上#include<set>的头文件)
10.
| lower_bound | 要求[first,last)是有序的, 查找大于等于val的最小的位置 |
upper_bound | 要求[first,last)是有序的, 查找大于val的最小位置 |
11.vector有关函数整理
操作 | 效果 |
c.pop_back() | 移除最后一个元素但不返回最后一个元素 |
c.erase(pos) | 删除pos位置的元素,返回下一个元素的位置 |
c.erase(beg,end) | 删除区间[beg,end]内所有元素,返回下一个元素的位置 |
c.clear() | 移除所有元素,清空容器 |
c.resize(num) | 将元素数量改为num(增加的元素用defalut构造函数产生,多余的元素被删除) |
c.resize(num,e) | 将元素数量改为num(增加的元素是e的副本) |
c.insert(pos,e) | 在pos位置插入元素e的副本,并返回新元素位置 |
c.insert(pos,n,e) | 在pos位置插入n个元素e的副本 |
c.insert(pos,beg,end) | 在pos位置插入区间[beg,end]内所有元素的副本 |
c.push_back(e) | 在尾部添加一个元素e的副本 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<int> s;
s.push_back(5);
s.push_back(45);
s.push_back(12);
s.push_back(8);
vector<int>::iterator f=s.begin();
s.insert(f,5,12);
for(f=s.begin();f!=s.end();f++)
{
cout<<*f<<" ";
}
return 0;
} 上图为使用迭代器对于insert连续插入多个元素函数的使用。
边栏推荐
- Use lambda function URL + cloudfront to realize S3 image back to source
- 微服务大行其道的今天,Service Mesh是怎样一种存在?
- [R language data science]: common evaluation indicators of machine learning
- Basic knowledge of C language
- 一波三折,终于找到src漏洞挖掘的方法了【建议收藏】
- 【牛客网刷题系列 之 Verilog快速入门】~ 使用函数实现数据大小端转换
- Why did you win the first Taosi culture award of 20000 RMB if you are neither a top R & D expert nor a sales Daniel?
- Logic is a good thing
- 力扣解法汇总241-为运算表达式设计优先级
- Distributed dynamic (collaborative) rendering / function runtime based on computing power driven, data and function collaboration
猜你喜欢

Summary of leetcode's dynamic programming 5

【修复版】仿我爱看电影网站模板/海洋CMS影视系统模板

2022-2-15 learning the imitation Niuke project - post in Section 2

【R语言数据科学】:机器学习常见评估指标
![[IOT completion. Part 2] stm32+ smart cloud aiot+ laboratory security monitoring system](/img/b2/e8f81ecda6f5f4fc65501aaf9f13cf.gif)
[IOT completion. Part 2] stm32+ smart cloud aiot+ laboratory security monitoring system

那个很努力的学生,高考失败了……别慌!你还有一次逆袭机会!

户外LED显示屏应该考虑哪些问题?

MIT team used graph neural network to accelerate the screening of amorphous polymer electrolytes and promote the development of next-generation lithium battery technology

【14. 区间和(离散化)】

一波三折,终于找到src漏洞挖掘的方法了【建议收藏】
随机推荐
微服务开发步骤(nacos)
[getting started with Django] 13 page Association MySQL "multi" field table (check)
Research Report on the development trend and competitive strategy of the global pipeline robot inspection camera industry
Research Report on the development trend and competitive strategy of the global axis measurement system industry
Leetcode (69) -- square root of X
Minimum spanning tree and bipartite graph in graph theory (acwing template)
Effet halo - qui dit qu'il y a de la lumière sur la tête est un héros
sqlilabs less10
Basic concepts of programming
Websocket (simple experience version)
Open source internship experience sharing: openeuler software package reinforcement test
TDengine 连接器上线 Google Data Studio 应用商店
Provincial election + noi Part VIII fraction theory
问题随记 —— Oracle 11g 卸载
That hard-working student failed the college entrance examination... Don't panic! You have another chance to counter attack!
30 Devops interview questions and answers
sqlilabs less10
Research Report on the development trend and competitive strategy of the global navigation simulator industry
力扣解法汇总241-为运算表达式设计优先级
leetcode622. Design cycle queue (C language)