当前位置:网站首页>期末琐碎知识点再整理
期末琐碎知识点再整理
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连续插入多个元素函数的使用。
边栏推荐
- Don't want to knock the code? Here comes the chance
- MIT团队使用图神经网络,加速无定形聚合物电解质筛选,促进下一代锂电池技术开发
- [R language data science]: common evaluation indicators of machine learning
- 【牛客网刷题系列 之 Verilog快速入门】~ 使用函数实现数据大小端转换
- Go integrates logrus to realize log printing
- Today, with the popularity of micro services, how does service mesh exist?
- Leetcode (69) -- square root of X
- Provincial election + noi Part VIII fraction theory
- SWT / anr problem - how to capture performance trace
- Research Report on the development trend and competitive strategy of the global traditional computer industry
猜你喜欢
sqlilabs less13
Minimum spanning tree and bipartite graph in graph theory (acwing template)
TDengine 连接器上线 Google Data Studio 应用商店
Salesforce, Johns Hopkins, Columbia | progen2: exploring the boundaries of protein language models
So programmers make so much money doing private work? It's really delicious
2022-2-15 learning xiangniuke project - Section 1 filtering sensitive words
sqlilabs less9
C 语言基础
数据湖系列之一 | 你一定爱读的极简数据平台史,从数据仓库、数据湖到湖仓一体
C#学习笔记(5)类和继承
随机推荐
微服务大行其道的今天,Service Mesh是怎样一种存在?
Research Report on the development trend and competitive strategy of the global indexable milling cutter industry
Today, with the popularity of micro services, how does service mesh exist?
Research Report on the development trend and competitive strategy of the global powder filling machine industry
Provincial election + noi Part XI others
MySQL log
Research Report on the development trend and competitive strategy of the global chemical glassware industry
Develop small programs and official account from zero [phase III]
sqlilabs less9
Use the npoi package of net core 6 C to read excel Pictures in xlsx cells and stored to the specified server
Websocket (simple experience version)
sqlilabs less-11~12
百度上找的期货公司安全吗?期货公司怎么确定正规
Effet halo - qui dit qu'il y a de la lumière sur la tête est un héros
Research Report on the development trend and competitive strategy of the global ultrasonic scalpel system industry
Advanced C language
Minimum spanning tree and bipartite graph in graph theory (acwing template)
phpcms实现订单直接支付宝支付功能
[stage life summary] I gave up the postgraduate entrance examination and participated in the work. I have successfully graduated and just received my graduation certificate yesterday
[14. Interval sum (discretization)]