std::basic_string
從 cppreference.com
|
|
該頁由英文版wiki使用Google Translate機器翻譯而來。
該翻譯可能存在錯誤或用詞不當。鼠標停留在文本上可以看到原版本。你可以幫助我們修正錯誤或改進翻譯。參見說明請點擊這裡. |
| 在頭文件 <string> 中定義
|
||
| template< class CharT, |
||
類模板
basic_string存儲和處理字符類型的對象序列(即特化的std::char_traits對象或兼容的特性類)。 原文:
The class template
basic_string stores and manipulates sequences of char-like objects (that is, objects for which a specialization of std::char_traits or compatible traits class is provided). basic_string中的元素連續存儲,也就是說,對於一個basic_strings,[0, s.size())中的任意n都滿足&*(s.begin() + n) == &*s.begin() + n,或者,與之等價,一個指向s[0]的指針可以傳遞給函數,這個函數接收charT[]數組第一個元素的指針。 (since C++11)原文:
The elements of a
basic_string are stored contiguously, that is, for a basic_string s, &*(s.begin() + n) == &*s.begin() + n for any n in [0, s.size()), or, equivalently, a pointer to s[0] can be passed to functions that expect a pointer to the first element of a charT[] array. (since C++11)為常見字符類型提供的一些特化類:
| 在頭文件
<string> 中定義 | |
| 類型 | 定義 |
| std::string | std::basic_string<char> |
| std::wstring | std::basic_string<wchar_t> |
| std::u16string | std::basic_string<char16_t> |
| std::u32string | std::basic_string<char32_t> |
[編輯] 成員類型
| 成員類型 | 定義 |
traits_type
|
Traits
|
value_type
|
Traits::char_type
|
allocator_type
|
Allocator
|
size_type
|
無符號整型(通常是size_t) |
difference_type
|
有符號整型 (通常是ptrdiff_t) |
reference
|
Allocator::reference (until C++11)value_type& (since C++11)
|
const_reference
|
Allocator::const_reference (until C++11)const value_type& (since C++11)
|
pointer
|
Allocator::pointer (until C++11)std::allocator_traits<Allocator>::pointer (since C++11) |
const_pointer
|
Allocator::const_pointer (until C++11) std::allocator_traits<Allocator>::const_pointer (since C++11) |
iterator
|
RandomAccessIterator
|
const_iterator
|
隨機訪問常迭代器 |
reverse_iterator
|
std::reverse_iterator<iterator> |
const_reverse_iterator
|
std::reverse_iterator<const_iterator> |
[編輯] 成員函數
| 構造 basic_string (公共成員函數) | |
| 為字符串賦值 (公共成員函數) | |
| 為字符串賦值 (公共成員函數) | |
| 返回關聯的分配器 (公共成員函數) | |
| |
| 訪問指定位置的字符,帶邊界檢查 (公共成員函數) | |
| 訪問指定位置的字符 (公共成員函數) | |
| (C++11) |
訪問的第一個字符 (公共成員函數) |
| (C++11) |
訪問的最後一個字符 (公共成員函數) |
| 返回一個指針,指向一個字符串的第一個字符 原文: returns a pointer to the first character of a string (公共成員函數) | |
| 返回一個不可修改的C風格字符串 原文: returns a non-modifiable standard C character array version of the string (公共成員函數) | |
| |
| (C++11) |
返回指向字符串第一個元素的迭代器 原文: returns an iterator to the beginning (公共成員函數) |
| (C++11) |
返回指向字符串尾端的迭代器 (公共成員函數) |
| (C++11) |
返回一個指向字符串最後一個元素的反向迭代器 原文: returns a reverse iterator to the beginning (公共成員函數) |
| (C++11) |
返回一個指向字符串前端的反向迭代器 原文: returns a reverse iterator to the end (公共成員函數) |
| |
| 檢查字符串是否為空 (公共成員函數) | |
| 返回字符數量 (公共成員函數) | |
| 返回最大字符數量 原文: returns the maximum number of characters (公共成員函數) | |
| 預留存儲空間 (公共成員函數) | |
| 返回當前分配的存儲空間可容納的最大字符數量 原文: returns the number of characters that can be held in currently allocated storage (公共成員函數) | |
| (C++11) |
通過釋放未使用的內存減少內存使用 原文: reduces memory usage by freeing unused memory (公共成員函數) |
| |
| 刪除全部內容 (公共成員函數) | |
| 插入字符 (公共成員函數) | |
| 刪除字符 (公共成員函數) | |
| 向末尾添加字符 (公共成員函數) | |
| (C++11) |
刪除最後一個字符 (公共成員函數) |
| 向末尾添加字符(串) (公共成員函數) | |
| 向末尾添加字符(串) (公共成員函數) | |
| 比較兩個字符串 (公共成員函數) | |
| 替換出現的每一個指定的字符 原文: replaces every occurrence of specified characters (公共成員函數) | |
| 返回子字符串 (公共成員函數) | |
| 複製字符 (公共成員函數) | |
| 改變存儲的字符數 原文: changes the number of characters stored (公共成員函數) | |
| 交換字符串的內容 (公共成員函數) | |
| |
| 在字符串中尋找字符(串) (公共成員函數) | |
| 尋找字符(串)最後一次出現的位置 原文: find the last occurrence of a substring (公共成員函數) | |
| 尋找字符串中任意字符第一次出現的位置 (公共成員函數) | |
| 尋找字符串中任意字符第一次缺失的位置 (公共成員函數) | |
| 尋找字符串中任意字符最後一次出現的位置 (公共成員函數) | |
| 尋找字符串中任意字符最後一次缺失的位置 (公共成員函數) | |
| |
| [靜態的]</div></div>
|
特殊值。確切的含義取決於具體情況。 原文: special value. The exact meaning depends on the context (公共靜態成員常量) |
[編輯] 非成員函數
| 連接兩個字符串或字符和字符串 (函數模板) | |
| 按字典順序比較兩個字符串 原文: lexicographically compares two strings (函數模板) | |
| 特化的std::swap算法 (函數模板) | |
| |
| 在字符串上執行流式I/O (函數模板) | |
| 從的I/O流讀取數據,並寫入字符串 原文: read data from an I/O stream into a string (函數) | |
| |
| (C++11) (C++11) (C++11) |
將字符串轉換為有符號整數 原文: converts a string to an signed integer (函數) |
| (C++11) (C++11) |
將字符串轉換為無符號整數 原文: converts a string to an unsigned integer (函數) |
| (C++11) (C++11) (C++11) |
將字符串轉換為浮點值 原文: converts a string to an floating point value (函數) |
| (C++11) |
將整數或浮點值轉換為 string 原文: converts an integral or floating point value to string (函數) |
| (C++11) |
將整數或浮點值轉換為 wstring 原文: converts an integral or floating point value to wstring (函數) |
[編輯] 字面值
| 定義於
std::literals::string_literals 名字空間 | |
| (C++14) |
將字符數組字面值轉換為 basic_string (函數) |
[編輯] 輔助類
| (C++11) (C++11) (C++11) (C++11) |
支持字符串的哈希函數 (類模板特化) |