STL之string
来源:互联网 发布:总做白日梦知乎 编辑:程序博客网 时间:2024/06/15 01:01
原文地址:http://www.cplusplus.com/reference/string/string/
string
字符串是表示字符序列的对象。
标准字符串类使用类似于标准容器字节的接口来提供对这些对象的支持,但是添加专门用于以单字节字符串操作的功能。
使用string类之前必须加上<string>头文件:#include<string>;
构造函数
string();
string (const string& str);
string (const string& str, size_t pos, size_t len = npos);
string (const char* s);
string (const char* s, size_t n);
string (size_t n, char c);
template <class InputIterator> string (InputIterator first, InputIterator last);
string (initializer_list<char> il);
string (string&& str) noexcept;
成员函数
Member functions
- (constructor)
- Construct string object (public member function )构造函数
- (destructor)
- String destructor (public member function )析构函数
- operator=
- String assignment (public member function )重载=
Iterators:
- begin
- Return iterator to beginning (public member function )获得begin迭代器
- end
- Return iterator to end (public member function )获得end迭代器
- rbegin
- Return reverse iterator to reverse beginning (public member function )
- rend
- Return reverse iterator to reverse end (public member function )
- cbegin
- Return const_iterator to beginning (public member function )获得const begin迭代器
- cend
- Return const_iterator to end (public member function )获得const end迭代器
- crbegin
- Return const_reverse_iterator to reverse beginning (public member function )
- crend
- Return const_reverse_iterator to reverse end (public member function )
Capacity:
- size
- Return length of string (public member function )字符串长度
- length
- Return length of string (public member function )
- max_size
- Return maximum size of string (public member function )
- resize
- Resize string (public member function )
- capacity
- Return size of allocated storage (public member function )
- reserve
- Request a change in capacity (public member function )
- clear
- Clear string (public member function )清空String类
- empty
- Test if string is empty (public member function )判断是否为空
- shrink_to_fit
- Shrink to fit (public member function )
Element access:
- operator[]
- Get character of string (public member function )重载下标
- at
- Get character in string (public member function )下标索引
- back
- Access last character (public member function )返回最后一个字符的左值
- front
- Access first character (public member function )返回第一个字符的左值
Modifiers:
- operator+=
- Append to string (public member function )
- append
- Append to string (public member function )
- push_back
- Append character to string (public member function )添加字符串到字符串末尾
- assign
- Assign content to string (public member function )为字符串分配一个新值,替换其当前内容
- insert
- Insert into string (public member function )在指示下标前插入字符
- erase
- Erase characters from string (public member function )删除字符串
- replace
- Replace portion of string (public member function )替代字符串
- swap
- Swap string values (public member function )交换string的值
- pop_back
- Delete last character (public member function )删除最后一个字符
String operations:
- c_str
- Get C string equivalent (public member function )
- data
- Get string data (public member function )
- get_allocator
- Get allocator (public member function )
- copy
- Copy sequence of characters from string (public member function )
- find
- Find content in string (public member function )搜索
- rfind
- Find last occurrence of content in string (public member function )
- find_first_of
- Find character in string (public member function )
- find_last_of
- Find character in string from the end (public member function )
- find_first_not_of
- Find absence of character in string (public member function )
- find_last_not_of
- Find non-matching character in string from the end (public member function )
- substr
- Generate substring (public member function )获得字串
- compare
- Compare strings (public member function )比较
数值和String的相互转换(非string成员函数)
- to_string(val)
- 返回数值val的string表示
- stoi(s,p,b)
- 返回s的字串的int数值,b表示转换基数,默认为10,p用来保存s中第一个非数值字符的下标,默认为0
- stol(s,p,b)
- 返回s的字串的long数值
- stoul(s,p,b)
- 返回s的字串的unsigned long数值
- stoll(s,p,b)
- stof(s,p)
- 返回s的字串的float数值
- stod(s,p)
- 返回s的字串的double数值
- stold(s,p)
- 返回s的字串的long double数值
阅读全文
0 0
- 【STL】STL之string类
- STL之string
- C++STL之string
- stl之string
- C++STL之string
- STL 之 string
- STL之String
- STL总结之string
- STL 之 string
- C++STL之string
- C++ STL之string
- C++STL之string
- STL之string
- c++STL之string
- STL之string
- C++STL之string
- STL之string
- STL之string
- 程序员30岁的殇
- OkHttp3源码分析[缓存策略]
- 取出List<String>中的数据加到StringBuffer中去
- ECharts3基础教程(一)简单上手篇
- Python3爬虫(二)保存抓取网页的html
- STL之string
- 比特币多重签名的现状(2017年)
- 如何减少http请求
- 简单选择排序到底稳不稳定 简单选择排序到底稳不稳定
- js中json
- 白话Spring(基础篇)---AOP(execution表达式)
- unity 利用差值实现相机跟随与轴值实现人物拉近
- curl 使用举例详解(五)
- Spring和ActiveMQ整合的完整实例