C++:string 头文件详解和 string 的使用

<string> 


header

该 header 介绍字符串类型,字符特征和一组转换函数


类模板

 (class template )

basic_string

通用字符串类模板

char_traits

char型字符串模板


类的实例

 (class )

string

String类

u16string 

16位 String 字符类

u32string 

32位 String 字符类

wstring

宽 string 类


函数

(function template )

string 转换成其他

stoi 

转换 string -> integer 

stol 

转换 string -> long int 

stoul 

转换 string -> unsigned integer 

stoll 

转换 string -> long long 

stoull 

转换 string -> unsigned long long 

stof 

转换 string -> float

stod 

转换 string -> double 

stold 

转换 string -> long double


其他转换成strings

(function )

to_string 

转换 numerical value -> string

to_wstring 

转换 numerical value -> wide string


访问元素

(function template )

begin 

将迭代器返回到开头(增长方向:begin -> end)

end 

将迭代器返回到结尾


std::string


class


迭代器操作:

 (public member function )

begin

将迭代器返回到开头(增长方向:begin -> end)

end

将迭代器返回到结尾

rbegin

返回反向迭代器以反向开始(增长方向:rbegin -> rend)

rend

将反向迭代器返回到反向结束

cbegin (C++11)

将const_iterator返回到开头(与begin类似,区别在于begin指向的值可以改变,cbegin指向的值不可改变)

cend (C++11)

将const_iterator返回到开头末尾

crbegin (C++11)

返回const_reverse_iterator以反向开始

crend (C++11)

将const_reverse_iterator返回到反向结束


容量函数:

 (public member function )

size

返回字符串的长度

length

返回字符串的长度

max_size

返回可以拓展的最大容量

resize

改变目前字符串的长度

capacity

返回分配给字符串的大小

reserve

改变容器的预留空间的大小

clear

清空字符串的内容

empty

判断字符串是否为空

shrink_to_fit (C++11)

缩小字符串预留空间到较适合的程度


元素访问:

 (public member function )

operator[]

获取字符串的字符

at

直接访问指定位置的元素,指定位置超出有效范围会报出异常

back (C++11)

返回字符串的尾部字符

front (C++11)

返回字符串的首部字符


字符串操作:

 (public member function )

operator+=

附加其他字符串内容到该字符串

append

附加其他字符串内容到该字符串

push_back

将字符附加到字符串

assign

为字符串分配一个新值,替换其当前内容

insert

指定位置插入字符,或者插入字符串

erase

擦除指定长度的字符串

replace

在指定位置使用新的值代替原来的字符串的部分值

swap

交换两个字符串的内容

pop_back (C++11)

删除最后一个字符


字符串操作:

 (public member function )

c_str

获取等效的 C 字符串

data

获取等效的 C 字符串

get_allocator

Get allocator (public member function )

copy

获取字符串到指定的 C 字符串

find

在字符串中查找指定内容

rfind

在字符串中查找最后出现的内容

find_first_of

在字符串中查找字符

find_last_of

从末尾反向查找字符串中的字符

find_first_not_of

在字符串中查找非指定的所有字符的字符

find_last_not_of

从末尾反向查找非指定的所有字符的字符

substr

生成包含原字符串的所有值或者部分值的副本

compare

比较两个字符串


Member constants

(public static member constant )

npos

Maximum value for size_t (public static member constant )


非成员函数重载

 (function )

operator+

连接字符串

relational operators

字符串的关系运算符

swap

交换两个字符串的值

operator>>

从流中提取字符串

operator<<

将字符串插入到流

getline

获取从流到字符串的行

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值