当前位置:网站首页>String class and learning documents
String class and learning documents
2022-06-10 10:58:00 【Hua Weiyun】
【 Write it at the front 】
Here we have to learn to read documents by ourselves , Because that's it string Class, there are more than 100 interface functions , Then I can't remember , We usually use about twenty , Generally, we study it, which is commonly used , Others are probably familiar with their functions , If you really want to use it, then check the documents . You can see that in fact string Is a sequence table that manages character arrays , Because character arrays are widely used ,C++ Just for one string class , Due to coding reasons , It's written as a template . in the light of string, Generally, it has three members —— char* _str、size_t _size、size_t _capacity, Let's simulate and implement string You'll see , Secondly, when learning deep and shallow copies, we only use char* _str.
C++ Strictly speaking, there are two document libraries : Note that the former is not C++ Official website documentation , The latter is . Here we take the official documents as a reference , Because it's messy , Usually use it cplusplus That's enough .
In addition, there is a deep and shallow copy of knowledge about classes and objects, which we will add here .
One 、 Why study string class
C Strings in languages
C In language , String is based on ‘\0’ A collection of characters at the end , For ease of operation ,C The standard library provides some str Series of library functions ,
But these library functions are separate from strings , Not quite in line with OOP Thought , And the underlying space needs to be managed by users , A little carelessness can
And cross-border visits .
Two interview questions ( Don't explain for the moment )
stay OJ in , Questions about strings are basically based on string Class , And in routine work , For simplicity 、 convenient 、 quick , Basically use string class , Few people use C String manipulation functions in the library .
Two 、 In the standard library string class
string class ( understand )
- A string is a class that represents a sequence of characters .
- The standard string class provides support for such objects , Its interface is similar to that of a standard character container , However, a design feature has been added specifically for manipulating single byte character strings .
- string Class is to use char( As its character type , Use its default char_traits And distributor type ( More information about templates , see also basic_string).
- string Class is basic_string An instance of the template class , It USES char To instantiate basic_string Template class , And use char_traits and allocator As basic_string Default parameters ( For more template information, please refer to basic_string).
- Be careful , This class handles bytes independently of the encoding used : If used to handle multi byte or variable length characters ( Such as UTF-8) Sequence , All members of this class ( Such as length or size ) And its iterators , Will still be in bytes ( Not actually encoded characters ) To operate .
summary :
- string Is a string class that represents a string .
- The interface of this class is basically the same as that of a regular container , And added some special operations for string General operation of .
- string At the bottom, it's actually :basic_string Alias of template class ,typedef basic_string<char, char_traits, allocator> string;.
- Cannot manipulate sequences of multibyte or variable length characters .
- In the use of string Class time , Must contain string Header files and using namespace std;.

#include<string>#include<iostream>using namespace std;int main(){ cout << sizeof(char) << endl; cout << sizeof(wchar_t) << endl; char arr1[] = "hello bit"; char arr2[] = " The bit "; return 0;}explain
For characters ,C++ Two types are proposed in , At this stage, the contact is the first .
You can see that one of the results is 1 and 2, This thing has something to do with coding .
code
Only binary is stored in the computer 0 and 1, How to express words ???
At this time, the corresponding coding table is established :
ASCII > English support
1Byte = 8Bit,0 - 255 ASCII The coding table is right 256 A value establishes a corresponding representation value
GBK > China has formulated , Commonly used in windows Next
In the early windows In order to enter the Chinese market , Just use this codeutf-8 > Universal , compatible ASCII, Commonly used in Linux Next
Countries all over the world are beginning to use computers , In the early days, computers could only express English , Words that cannot represent other countries , So you need to create your own coding table , But it's very messy to do their own things , So there it is utf-8, In the early days UniCode
So according to incomplete statistics, there are about 100000 Chinese characters , So we use 2 Bytes , Probably means 6 Ten thousand states
边栏推荐
- 高考志愿填报,城市、学校与专业怎么选?
- 【黄啊码】我用这个方式清理了谷歌浏览器的控制台
- MySQL practice 45 lectures_ 8_ Deepen the understanding of MySQL repeatable reading from a problem
- [time series prediction] esrnn paper reading
- Switch the Taobao image of NPM
- 诺思格医药通过注册:年营收6亿 实控人武杰为美国籍
- PAT甲级 1126 欧拉路径
- 2022 examination questions and answers of labor worker post skills (labor worker)
- PID光离子化检测器用于电厂压缩空气含油量的在线监测
- PAT 甲级 1134 顶点覆盖
猜你喜欢

杰理之BLE timer 时钟源不能选 OSC 晶振【篇】

高考志愿填报,城市、学校与专业怎么选?

基于分布式数据库本身的定时备份方法

Leetcode 2000. Reverse word prefix

单片机触发器或非门工作原理以及用途

渡远户外冲刺深交所:年营收3.5亿 林锡臻家族色彩明显

更耐用的遊戲真無線耳機,電池超大續航持久,英雄G1上手

vite的public目录

Noise reduction flagship with excellent sound quality, female poison must be selected, Mo3 experience of shell Prince

Fcpx plug-in: premiumvfx animation presets v1.0.1 Special Edition
随机推荐
Modstartcms enterprise content site building system (supporting laravel9) v4.1.0
杰理之长按复位及高电平复位【篇】
渡远户外冲刺深交所:年营收3.5亿 林锡臻家族色彩明显
How to choose cities, schools and majors for the college entrance examination?
【无标题】
PV操作每日一题-餐厅上菜问题
More durable game real wireless headset with large battery and long endurance. Hero G1 can use it
二进制、八进制、十进制、十六进制间互转(整数加小数)
Review the growth evaluation of central enterprises and listed companies
MIT6.824-lab2D-2022(日志压缩详细讲解)
微信小程序注册流程详解
How to state clearly and concisely the product requirements?
ColorUI配色详情
Open source byte design idea
PV操作每日一题-橘子苹果问题(初阶版)
[high concurrency] about optimistic lock and pessimistic lock, the interviewer of ant financial asked me these questions!!
MySQL architecture
数商云通讯行业数字化供应链协同系统:赋能通讯企业改善供应业务,增强市场竞争力
Mixin -- mixed
golang CLI框架--cobra