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) | (C++11 起) |
basic_string( basic_string&& other ) |
(8) | (C++11 起) |
basic_string( basic_string&& other, const Allocator& alloc ); |
(8) | (C++11 起) |
basic_string( std::initializer_list<CharT> init, const Allocator& alloc = Allocator() ); |
(9) | (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) count
ch
副本.原文:
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) 線性
count
5) 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
[編輯] 示例
本章尚未完成 原因:暫無示例 |
[編輯] 另請參閱
為字元串賦值 (公共成員函數) | |
為字元串賦值 (公共成員函數) |