- 
                Notifications
    You must be signed in to change notification settings 
- Fork 975
          Clean up basic_string class reference
          #5689
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a82987b
              d7a7af8
              b49ef08
              ba3cf7a
              85624a1
              a81ce6c
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,13 +1,13 @@ | ||||||
| --- | ||||||
| title: "basic_string Class" | ||||||
| title: "basic_string class" | ||||||
| description: "API reference for the Standard C++ string class, `basic_string`." | ||||||
| ms.date: 07/11/2023 | ||||||
| f1_keywords: ["xstring/std::basic_string", "xstring/std::basic_string::allocator_type", "xstring/std::basic_string::const_iterator", "xstring/std::basic_string::const_pointer", "xstring/std::basic_string::const_reference", "xstring/std::basic_string::const_reverse_iterator", "xstring/std::basic_string::difference_type", "xstring/std::basic_string::iterator", "xstring/std::basic_string::npos", "xstring/std::basic_string::pointer", "xstring/std::basic_string::reference", "xstring/std::basic_string::reverse_iterator", "xstring/std::basic_string::size_type", "xstring/std::basic_string::traits_type", "xstring/std::basic_string::value_type", "xstring/std::basic_string::append", "xstring/std::basic_string::assign", "xstring/std::basic_string::at", "xstring/std::basic_string::back", "xstring/std::basic_string::begin", "xstring/std::basic_string::c_str", "xstring/std::basic_string::capacity", "xstring/std::basic_string::cbegin", "xstring/std::basic_string::cend", "xstring/std::basic_string::clear", "xstring/std::basic_string::compare", "xstring/std::basic_string::copy", "xstring/std::basic_string::crbegin", "xstring/std::basic_string::crend", "xstring/std::basic_string::_Copy_s", "xstring/std::basic_string::data", "xstring/std::basic_string::empty", "xstring/std::basic_string::end", "xstring/std::basic_string::erase", "xstring/std::basic_string::find", "xstring/std::basic_string::find_first_not_of", "xstring/std::basic_string::find_first_of", "xstring/std::basic_string::find_last_not_of", "xstring/std::basic_string::find_last_of", "xstring/std::basic_string::front", "xstring/std::basic_string::get_allocator", "xstring/std::basic_string::insert", "xstring/std::basic_string::length", "xstring/std::basic_string::max_size", "xstring/std::basic_string::pop_back", "xstring/std::basic_string::push_back", "xstring/std::basic_string::rbegin", "xstring/std::basic_string::rend", "xstring/std::basic_string::replace", "xstring/std::basic_string::reserve", "xstring/std::basic_string::resize", "xstring/std::basic_string::rfind", "xstring/std::basic_string::shrink_to_fit", "xstring/std::basic_string::size", "xstring/std::basic_string::substr", "xstring/std::basic_string::ends_with", "xstring/std::basic_string::starts_with", "xstring/std::basic_string::swap", 'xstring/std::literals::string_literals', 'std::literals::string_literals', 'string_literals', 'xstring/std::literals::string_literals::operator "s', 'std::literals::string_literals::operator s'] | ||||||
| helpviewer_keywords: ["std::basic_string [C++]", "std::basic_string [C++], allocator_type", "std::basic_string [C++], const_iterator", "std::basic_string [C++], const_pointer", "std::basic_string [C++], const_reference", "std::basic_string [C++], const_reverse_iterator", "std::basic_string [C++], difference_type", "std::basic_string [C++], iterator", "std::basic_string [C++], npos", "std::basic_string [C++], pointer", "std::basic_string [C++], reference", "std::basic_string [C++], reverse_iterator", "std::basic_string [C++], size_type", "std::basic_string [C++], traits_type", "std::basic_string [C++], value_type", "std::basic_string [C++], append", "std::basic_string [C++], assign", "std::basic_string [C++], at", "std::basic_string [C++], back", "std::basic_string [C++], begin", "std::basic_string [C++], c_str", "std::basic_string [C++], capacity", "std::basic_string [C++], cbegin", "std::basic_string [C++], cend", "std::basic_string [C++], clear", "std::basic_string [C++], compare", "std::basic_string [C++], copy", "std::basic_string [C++], crbegin", "std::basic_string [C++], crend", "std::basic_string [C++], _Copy_s", "std::basic_string [C++], data", "std::basic_string [C++], empty", "std::basic_string [C++], end", "std::basic_string [C++], erase", "std::basic_string [C++], find", "std::basic_string [C++], find_first_not_of", "std::basic_string [C++], find_first_of", "std::basic_string [C++], find_last_not_of", "std::basic_string [C++], find_last_of", "std::basic_string [C++], front", "std::basic_string [C++], get_allocator", "std::basic_string [C++], insert", "std::basic_string [C++], length", "std::basic_string [C++], max_size", "std::basic_string [C++], pop_back", "std::basic_string [C++], push_back", "std::basic_string [C++], rbegin", "std::basic_string [C++], rend", "std::basic_string [C++], replace", "std::basic_string [C++], reserve", "std::basic_string [C++], resize", "std::basic_string [C++], rfind", "std::basic_string [C++], shrink_to_fit", "std::basic_string [C++], size", "std::basic_string [C++], starts_with", "std::basic_string [C++], ends_with","std::basic_string [C++], substr", "std::basic_string [C++], swap"] | ||||||
| ms.custom: devdivchpfy22 | ||||||
| --- | ||||||
|  | ||||||
| # `basic_string` Class | ||||||
| # `basic_string` class | ||||||
|  | ||||||
| The sequences controlled by an object of type `basic_string` are the Standard C++ string class and are referred to as strings, but they shouldn't be confused with the null-terminated C-style strings used throughout the C++ Standard Library. The Standard C++ string is a container that enables the use of strings as normal types, such as comparison and concatenation operations, iterators, C++ Standard Library algorithms, and copying and assigning with class allocator-managed memory. If you need to convert a Standard C++ string to a null-terminated C-style string, use the [`basic_string::c_str`](#c_str) member. | ||||||
|  | ||||||
|  | @@ -18,13 +18,13 @@ template <class CharType, class Traits = char_traits<CharType>, class Allocator | |||||
| class basic_string; | ||||||
| ``` | ||||||
|  | ||||||
| ### Parameters | ||||||
| ### Template parameters | ||||||
|  | ||||||
| *`CharType`*\ | ||||||
| The data type of a single character to be stored in the string. The C++ Standard Library provides specializations of this class template, with the type definitions [`string`](../standard-library/string-typedefs.md#string) for elements of type `char`, [`wstring`](../standard-library/string-typedefs.md#wstring), for `wchar_t`, [`u16string`](../standard-library/string-typedefs.md#u16string) for `char16_t`, and [`u32string`](../standard-library/string-typedefs.md#u32string) for `char32_t`. | ||||||
| The data type of a single character to be stored in the string. The C++ Standard Library provides specializations of this class template, with the type definitions [`string`](string-typedefs.md#string) for elements of type `char`, [`wstring`](string-typedefs.md#wstring), for `wchar_t`, [`u16string`](string-typedefs.md#u16string) for `char16_t`, and [`u32string`](string-typedefs.md#u32string) for `char32_t`. | ||||||
|  | ||||||
| *`Traits`*\ | ||||||
| Various important properties of the `CharType` elements in a basic_string specialization are described by the class `Traits`. The default value is `char_traits`<`CharType`>. | ||||||
| Various important properties of the `CharType` elements in a `basic_string` specialization are described by the class `Traits`. The default value is `char_traits`<`CharType`>. | ||||||
|  | ||||||
| *`Allocator`*\ | ||||||
| The type that represents the stored allocator object that encapsulates details about the string's allocation and deallocation of memory. The default value is `allocator<CharType>`. | ||||||
|  | @@ -117,22 +117,22 @@ The headers that define `basic_string` also define the following [user-defined l | |||||
| | Declaration | Description | | ||||||
| |--|--| | ||||||
| | `inline string operator"" s(const char* str, size_t len)` | Returns: `string(str, len)` | | ||||||
| | `inline string operator"" s(const wchar_t* str, size_t len)` | Returns: `wstring(str, len)` | | ||||||
| | `inline wstring operator"" s(const wchar_t* str, size_t len)` | Returns: `wstring(str, len)` | | ||||||
| | `inline basic_string<char8_t> operator"" s(const char8_t* str, size_t len)` | Returns: `basic_string<char8_t>(str, len)` | | ||||||
| | `inline u16string operator"" s(const char16_t* str, size_t len)` | Returns: `u16string(str, len)` | | ||||||
| | `inline u32string operator"" s(const char32_t* str, size_t len)` | Returns: `u32string(str, len)` | | ||||||
|  | ||||||
| ## Remarks | ||||||
|  | ||||||
| If a function is asked to generate a sequence longer than [`max_size`](#max_size) elements, the function reports a length error by throwing an object of type [`length_error`](../standard-library/length-error-class.md). | ||||||
| If a function is asked to generate a sequence longer than [`max_size`](#max_size) elements, the function reports a length error by throwing an object of type [`length_error`](length-error-class.md). | ||||||
|  | ||||||
| References, pointers, and iterators that designate elements of the controlled sequence can become invalid after any call to a function that alters the controlled sequence, or after the first call to a non-`const` member function. | ||||||
|  | ||||||
| ## Requirements | ||||||
|  | ||||||
| **Header:** \<string> | ||||||
| **Header:** `<string>` | ||||||
|  | ||||||
| **Namespace:** std | ||||||
| **Namespace:** `std` | ||||||
|  | ||||||
| ## <a name="allocator_type"></a> `basic_string::allocator_type` | ||||||
|  | ||||||
|  | @@ -279,7 +279,7 @@ int main( ) | |||||
| // appending one string to another in two ways, | ||||||
| // comparing append and operator [ ] | ||||||
| string str1d ( "Hello " ), str2d ( "Wide " ), str3d ( "World " ); | ||||||
| cout << "The string str2d is: " << str2d << endl; | ||||||
| cout << "The string str2d is: " << str2d << endl; | ||||||
| str1d.append ( str2d ); | ||||||
| cout << "The appended string str1d is: " | ||||||
| << str1d << "." << endl; | ||||||
|  | @@ -316,7 +316,7 @@ Appending the 1st part of the C-string cstr1b to string str1 gives: Hello Out. | |||||
| The string str2c is: Wide World | ||||||
| The appended string str1 is: Hello World. | ||||||
|  | ||||||
| The string str2d is: Wide | ||||||
| The string str2d is: Wide | ||||||
| The appended string str1d is: Hello Wide . | ||||||
| The doubly appended string str1 is: Hello Wide World . | ||||||
|  | ||||||
|  | @@ -379,10 +379,10 @@ The source string whose characters are to be assigned to the target string. | |||||
| The character value to be assigned. | ||||||
|  | ||||||
| *`first`*\ | ||||||
| An input iterator, const_pointer, or const_iterator addressing the first character in the range of the source string to be assigned to the target range. | ||||||
| An input iterator, `const_pointer`, or `const_iterator` addressing the first character in the range of the source string to be assigned to the target range. | ||||||
|  | ||||||
| *`last`*\ | ||||||
| An input iterator, const_pointer, or const_iterator addressing the one beyond the last character in the range of the source string to be assigned to the target range. | ||||||
| An input iterator, `const_pointer`, or `const_iterator` addressing the one beyond the last character in the range of the source string to be assigned to the target range. | ||||||
|  | ||||||
| *`off`*\ | ||||||
| The position at which new characters will start to be assigned. | ||||||
|  | @@ -417,7 +417,7 @@ int main( ) | |||||
| << str1a << "." << endl << endl; | ||||||
|  | ||||||
| // The second member function assigning a specific | ||||||
| // number of the of characters a C-string to a string | ||||||
| // number of the characters of a C-string to a string | ||||||
| 
     | ||||||
| // number of the characters of a C-string to a string | |
| // number of characters of a C-string to a string | 
    
      
    
      Copilot
AI
    
    
    
      Sep 24, 2025 
    
  
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a grammatical error. "less that zero" should be "less than zero".
Uh oh!
There was an error while loading. Please reload this page.