std::basic_string::basic_string
来自cppreference.com
< cpp | string | basic string
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| explicit basic_string( const Allocator& alloc = Allocator() ); |
(1) | |
| basic_string( size_type count, CharT ch, |
(2) | |
| basic_string( const basic_string& other, size_type pos, |
(3) | |
| basic_string( const CharT* s, size_type count, |
(4) | |
| basic_string( const CharT* s, const Allocator& alloc = Allocator() ); |
(5) | |
| template< class InputIt > basic_string( InputIt first, InputIt last, |
(6) | |
| basic_string( const basic_string& other ); |
(7) | |
| basic_string( const basic_string& other, const Allocator& alloc ); |
(7) | (since C++11) |
| basic_string( basic_string&& other ) |
(8) | (since C++11) |
| basic_string( basic_string&& other, const Allocator& alloc ); |
(8) | (since C++11) |
| basic_string( std::initializer_list<CharT> init, const Allocator& alloc = Allocator() ); |
(9) | (since C++11) |
从各种数据源和构造新的字符串,可以使用用户提供的分配器
1) alloc.原文:
Constructs new string from a variety of data sources and optionally using user supplied allocator
alloc.默认构造函数。构造空字符串.
2) 原文:
Default constructor. Constructs empty string.
构造的字符串与字符
3) countch副本.原文:
Constructs the string with
count copies of character ch.构造字符串的一个子串
4) [pos, pos+count)other。如果所请求的子持续过去的结尾的字符串,或者如果count == npos,所得到的子字符串是[pos, size())。如果pos >= other.size(),std::out_of_range被抛出.原文:
Constructs the string with a substring
[pos, pos+count) of other. If the requested substring lasts past the end of the string, or if count == npos, the resulting substring is [pos, size()). If pos >= other.size(), std::out_of_range is thrown.count的第一个字符的字符串所指向的s构造的字符串。 s可以包含空字符。 s不能是NULL指针.原文:
Constructs the string with the first
count characters of character string pointed to by s. s can contain null characters. s must not be a NULL pointer.构造的字符串以NULL结尾的字符串的内容所指向的
s。字符串的长度是由第一个空字符。 s不能是NULL指针.原文:
Constructs the string with the contents of null-terminated character string pointed to by
s. The length of the string is determined by the first null character. s must not be a NULL pointer.6) Constructs the string with the contents of the range [first, last).
7) Copy constructor. Constructs the string with the copy of the contents of other.
8) Move constructor. Constructs the string with the contents of other using move semantics.
9) Constructs the string with the contents of the initializer list init.
目录 |
[编辑] 参数
| alloc | - | 使用该字符串的所有内存分配的分配器
原文: allocator to use for all memory allocations of this string |
| count | - | 结果字符串的大小
|
| ch | - | 初始化字符串的值
|
| first, last | - | 范围内复制的字符
|
| s | - | 作为源use
初始化字符串的一个字符串的指针 原文: pointer to a character string to use as source to initialize the string with |
| other | - | 另一个字符串作为源使用初始化字符串
原文: another string to use as source to initialize the string with |
| init | - | 初始化列表中初始化字符串
原文: initializer list to initialize the string with |
| 类型要求 | ||
-InputIt 必须满足 InputIterator 的要求。
| ||
[编辑] 复杂度
1)不变
2-4) 线性
count5) linear in length of s
first和last之间的距离呈线性关系原文:
linear in distance between
first and last线性大小
8) other不变。如果
9) alloc,并给出alloc != other.get_allocator(),则采用线性.原文:
constant. If
alloc is given and alloc != other.get_allocator(), then linear.线性大小
init[编辑] 示例
| 本章尚未完成 原因:暂无示例 |
[编辑] 另请参阅
| 为字符串赋值 (公共成员函数) | |
| 为字符串赋值 (公共成员函数) |