当前位置:网站首页>Final summary of freshman semester (supplement knowledge loopholes)
Final summary of freshman semester (supplement knowledge loopholes)
2022-06-24 04:26:00 【Take you to learn code】
Near the final exam , With the help of C++ Primer Plus This book , Supplement relevant knowledge and review old knowledge points
Catalog
2、 The understanding of array names
3、 The basics of function pointers
(1) Get the address of the function
The difference between reference and pointer
make_pair and pair The difference between
find Function combination map(multimap) Lookup
How container elements are inserted
Constructors 、 Destructors and file operations
Shallow replication and deep replication
1、 Unsigned type
Unsigned types are a less common knowledge point , It is precisely because it is not used very often , So I forgot .
int、short、long、long long These four types belong to the symbol type , They all have corresponding unsigned variants that cannot store negative values , The advantage is to increase the maximum value that a variable can store ( Is to give the space of a negative number to a positive number ) Of course , Only if the value is not negative , Only unsigned types should be used . Such as population 、 The number of trees, etc . Create an unsigned version of a basic type , Just use keywords unsigned that will do .
for example :
unsigned short change;
unsigned int a;
unsigned c; // It also refers to the unsigned type corresponding to the integer
unsigned long f;
unsigned long long v;
2、 The understanding of array names
Array names are treated as pointers .c++ Interpret the array name as the address of its first element .
3、 The basics of function pointers
(1) Get the address of the function
Just use the function name ( It's not followed by parameters ) You can get the address of the function , for instance L If think() Is a function , that think Is the address of the function , Just pass the function as an argument , Function name must be passed . At this point, it is necessary to distinguish whether the address of the function or the return value of the function is passed .
process(think);// Pass on think The address to progress()
thought(think());// Pass on think() The return value of is given to thought()
(2) Declared function pointer
When declaring a pointer to a data type , You must specify the type that the pointer points to . Also when declaring a pointer to a function , You must also specify the type of function the pointer points to .
4、 Inline function
About the format :
Add the keyword before the function declaration inline
Add keywords to the function definition inline
5、 quote
A reference variable can be understood as an alias for a defined variable . The main function of a reference variable is to use it as a formal parameter of a function . By using reference variables as parameters , The function will use the raw data , Not a copy , In plain terms, it means changing any of the values , Another variable will follow .( In this way , Except pointer , References also provide a very convenient way for functions to deal with large structures )
Here's an example :
#include<iostream>
using namespace std;
int main()
{ int a=101;
int &b=a;
return 0;}
// Please note that , Of the following statement & Operator is not an address operator , Among them &a Express a The address of the referenced variable
int &a=b;Simple examples help understand :
#include<iostream>
using namespace std;
int main()
{
int a;
int &bb=a;
a=100;
cout<<&bb; // Output bb The corresponding address ( It should be with a The address of is the same )
cout<<endl<<bb; // Output bb( That is to say a Value , because bb Refer to the a)
return 0;}The difference between reference and pointer
There are some subtle differences between references and pointers , For example, you must initialize a reference before declaring it , But not like a pointer , Declare before assign .
6、 File operations
Reading documents
fstream It refers to the file stream containing write and read , As defined here a Is a file stream object , The following prescribed reading and writing methods are out That is, writing to a file . hinder is_open function , It is used to judge whether the file is opened .
a<<"......" It refers to the contents written to the file . Every time I run , These are the contents of the generated file , the reason being that out Write mode of , Each run will first delete the information in the previous file , If you want to make a tail adding operation , Then it should be changed to app To read and write files . In this way, the records will be preserved , Make ATM It should be used to simulate the system app How to operate .
After the operation is completed , Don't forget to close the link corresponding to the file .
Be careful : When there is no generated file , The system will automatically generate a file with this name . If so in( Read file operation ), So it's a mistake , If so out, Will be generated automatically .
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
fstream a;
a.open("test.txt",ios::out);
if(!a.is_open())
cout<<"can not open the file";
a<<" The exam is coming soon, and I won't do anything "<<endl<<" Hold on to the last minute !"<<endl;
a.close();
return 0;
} Writing documents
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
fstream s;
string message;
s.open(" Read and write operation of the file .txt",ios::in);
if(s.is_open())
{
cout<<" The file was successfully opened or created "<<endl;
}
else
cout<<" File opening failure ";
s>>message;
s.close();
cout<<message;
return 0;}Read the information in the file read / write operation , Then output the obtained information , Follow up work .
make_pair and pair The difference between
make_pair():
There is no need to write the type , You can generate a pair object
example :
std::make_pair(42, '@');
It doesn't have to be written as :
std::pair<int, char>(42, '@')
find Function combination map(multimap) Lookup
algorithm Of the header file find().
Usage method :find(begin,end,value), It's usually used Containers .end() To determine whether the search is successful .
Parameters 1 Is the starting address of the container or array ( Containers .begin() Or array name ), It can also be any address , It is not illegal ;
Parameters 2 Is the address where the search ends ( Containers .end() Or array name + length ),value Is the character or string you want to find
A successful lookup will return the iterator ( Containers ) Or pointer ( Array ), Otherwise return to end()
find The return is an iterator
If you can't find , It will return end()
void operation::find_idnum(string idnum1)
{
m2=idnumc.find(idnum1); // map<string,int>idnumc;
if(m2!=idnumc.end())
{
cout<<" find "<<endl<<person[m2->second]; //vector<message>person;
}
}
use equal_range Search for multimap The element interval of the qualified content of .
Use multimap、map Is automatically sorted , Will sort the information , So use lower_bound and upper_bound The found range can be used efficiently .
How container elements are inserted
have access to for Loop or while Loop through the insert operation , But then write the course design ATM operation period , Discover the use of while There will be an error while cycling , Or use for Revolving insurance ( After all, use while You need to write a lot of statements when looping , There may be some differences .)
Constructors 、 Destructors and file operations
Constructors 、 Destructors tend to be less attractive , But when we combine it with file manipulation , Should be in their function body if read file and write file operation .
Shallow replication and deep replication
Shallow copy concept
● When initializing one object with another , Only data members are copied , Without copying resources , The replication method that makes two objects point to the same resource at the same time is called shallow replication .
namely : For data members of complex types Only the storage address is copied and No copy of stored content
● The default copy constructor does simple data copying , Shallow copy
边栏推荐
- [hot promotion] Tencent cloud enterprise cloud disk solution
- Understanding of structure in C language
- uni-app进阶之认证【day12】
- mysql - sql执行过程
- Submit sitemap to Baidu
- Advanced authentication of uni app [Day12]
- Naming of tables in MySQL
- Mac CentOS installation phpredis
- uni-app进阶之认证【day12】
- C语言自定义类型的介绍(结构体,枚举,联合体,位段)
猜你喜欢

Abnova荧光原位杂交(FISH)探针解决方案

How can the new generation of HTAP databases be reshaped in the cloud? Tidb V6 online conference will be announced soon!

openEuler社区理事长江大勇:共推欧拉开源新模式 共建开源新体系

多任务视频推荐方案,百度工程师实战经验分享

The official overclocking tool of Intel XTU supports win11 22h2 and 13th generation core Raptor Lake processors

外网访问svn服务器(外网访问部署在云上的svn服务器)

C语言自定义类型的介绍(结构体,枚举,联合体,位段)

微博国际版更名为微博轻享版

应用实践 | Apache Doris 整合 Iceberg + Flink CDC 构建实时湖仓一体的联邦查询分析架构

Opengauss version 3.0 source code compilation and installation guide
随机推荐
Huawei cloud gaussdb (for redis) unveiling issue 19: gaussdb (for redis) comprehensive comparison with CODIS
Through the fog: location notes of Flink crash with a multi component timeout
Understanding of structure in C language
Application practice | Apache Doris integrates iceberg + Flink CDC to build a real-time federated query and analysis architecture integrating lake and warehouse
uni-app进阶之认证【day12】
Multi task video recommendation scheme, baidu engineers' actual combat experience sharing
How to remote server is the price of the server expensive
web渗透测试----5、暴力破解漏洞--(9)MS-SQL密码破解
应用实践 | Apache Doris 整合 Iceberg + Flink CDC 构建实时湖仓一体的联邦查询分析架构
Introduction to C language custom types (structure, enumeration, union, bit segment)
Summary of Android interview questions in 2020 (elementary)
apipost接口断言详解
共建欧拉社区 共享欧拉生态|携手麒麟软件 共创数智未来
编译器是如何将芯片执行的第一个指令放到芯片起始地址的?
What is etcd and its application scenarios
由浅入深的混合精度训练教程
Cadence OrCAD Capture 批量修改网络名称的两种最实用的方法图文教程及视频演示
Worthington脱氧核糖核酸酶I特异性和相关研究
IDC, Youshang cloud data on cloud (COS) best practices
Naming of tables in MySQL