Skip to content

Commit d552bf5

Browse files
authored
Merge pull request #5689 from Rageking8/clean-up-basic-string-class-reference
Clean up `basic_string` class reference
2 parents 6d162f2 + 3b3f65c commit d552bf5

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

docs/standard-library/basic-string-class.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: "basic_string Class"
2+
title: "basic_string class"
33
description: "API reference for the Standard C++ string class, `basic_string`."
44
ms.date: 07/11/2023
55
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']
66
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"]
77
ms.custom: devdivchpfy22
88
---
99

10-
# `basic_string` Class
10+
# `basic_string` class
1111

1212
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.
1313

@@ -18,13 +18,13 @@ template <class CharType, class Traits = char_traits<CharType>, class Allocator
1818
class basic_string;
1919
```
2020
21-
### Parameters
21+
### Template parameters
2222
2323
*`CharType`*\
24-
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`.
24+
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`.
2525
2626
*`Traits`*\
27-
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`>.
27+
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`>.
2828
2929
*`Allocator`*\
3030
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
117117
| Declaration | Description |
118118
|--|--|
119119
| `inline string operator"" s(const char* str, size_t len)` | Returns: `string(str, len)` |
120-
| `inline string operator"" s(const wchar_t* str, size_t len)` | Returns: `wstring(str, len)` |
120+
| `inline wstring operator"" s(const wchar_t* str, size_t len)` | Returns: `wstring(str, len)` |
121121
| `inline basic_string<char8_t> operator"" s(const char8_t* str, size_t len)` | Returns: `basic_string<char8_t>(str, len)` |
122122
| `inline u16string operator"" s(const char16_t* str, size_t len)` | Returns: `u16string(str, len)` |
123123
| `inline u32string operator"" s(const char32_t* str, size_t len)` | Returns: `u32string(str, len)` |
124124
125125
## Remarks
126126
127-
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).
127+
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).
128128
129129
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.
130130
131131
## Requirements
132132
133-
**Header:** \<string>
133+
**Header:** `<string>`
134134
135-
**Namespace:** std
135+
**Namespace:** `std`
136136
137137
## <a name="allocator_type"></a> `basic_string::allocator_type`
138138
@@ -279,7 +279,7 @@ int main( )
279279
// appending one string to another in two ways,
280280
// comparing append and operator [ ]
281281
string str1d ( "Hello " ), str2d ( "Wide " ), str3d ( "World " );
282-
cout << "The string str2d is: " << str2d << endl;
282+
cout << "The string str2d is: " << str2d << endl;
283283
str1d.append ( str2d );
284284
cout << "The appended string str1d is: "
285285
<< str1d << "." << endl;
@@ -316,7 +316,7 @@ Appending the 1st part of the C-string cstr1b to string str1 gives: Hello Out.
316316
The string str2c is: Wide World
317317
The appended string str1 is: Hello World.
318318
319-
The string str2d is: Wide
319+
The string str2d is: Wide
320320
The appended string str1d is: Hello Wide .
321321
The doubly appended string str1 is: Hello Wide World .
322322
@@ -379,10 +379,10 @@ The source string whose characters are to be assigned to the target string.
379379
The character value to be assigned.
380380
381381
*`first`*\
382-
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.
382+
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.
383383
384384
*`last`*\
385-
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.
385+
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.
386386
387387
*`off`*\
388388
The position at which new characters will start to be assigned.
@@ -417,7 +417,7 @@ int main( )
417417
<< str1a << "." << endl << endl;
418418
419419
// The second member function assigning a specific
420-
// number of the of characters a C-string to a string
420+
// number of characters of a C-string to a string
421421
string str1b;
422422
const char *cstr1b = "Out There";
423423
cout << "The C-string cstr1b is: " << cstr1b << endl;
@@ -452,7 +452,7 @@ int main( )
452452
// number of characters of a certain value to a string
453453
string str1e ( "Hello " );
454454
str1e.assign ( 4 , '!' );
455-
cout << "The string str1 assigned with eclamations is: "
455+
cout << "The string str1 assigned with exclamations is: "
456456
<< str1e << endl << endl;
457457
458458
// The sixth member function assigning the value from
@@ -481,7 +481,7 @@ The string str1 newly assigned with string str2d is: Wide.
481481
The string str3d is: World.
482482
The string str1 reassigned with string str3d is: World.
483483
484-
The string str1 assigned with eclamations is: !!!!
484+
The string str1 assigned with exclamations is: !!!!
485485
486486
The string str2f is: Wide World
487487
The string str1 assigned a range of string str2f is: World.
@@ -512,7 +512,7 @@ The first element of the string has an index of zero and the following elements
512512
513513
The member [`operator[]`](#op_at) is faster than the member function `at` for providing read and write access to the elements of a string.
514514
515-
The member `operator[]` doesn't check whether the index passed as a parameter is valid but the member function `at` does and so should be used if the validity isn't certain. An invalid index, which is an index less that zero or greater than or equal to the size of the string, passed to the member function `at` throws an [`out_of_range` Class](../standard-library/out-of-range-class.md) exception. An invalid index passed to the `operator[]` results in undefined behavior, but the index equal to the length of the string is a valid index for const strings and the operator returns the null-character when passed this index.
515+
The member `operator[]` doesn't check whether the index passed as a parameter is valid but the member function `at` does and so should be used if the validity isn't certain. An invalid index, which is an index less than zero or greater than or equal to the size of the string, passed to the member function `at` throws an [`out_of_range` Class](out-of-range-class.md) exception. An invalid index passed to the `operator[]` results in undefined behavior, but the index equal to the length of the string is a valid index for const strings and the operator returns the null-character when passed this index.
516516
517517
The reference returned may be invalidated by string reallocations or modifications for the non-`const` strings.
518518
@@ -662,10 +662,10 @@ The index of a character in a string that is the first to be used to initialize
662662
The character value to be copied into the string being constructed.
663663
664664
*`first`*\
665-
An input iterator, const_pointer, or const_iterator addressing the first element in the source range to be inserted.
665+
An input iterator, `const_pointer`, or `const_iterator` addressing the first element in the source range to be inserted.
666666
667667
*`last`*\
668-
An input iterator, const_pointer, or const_iterator addressing the position of the one beyond the last element in the source range to be inserted.
668+
An input iterator, `const_pointer`, or `const_iterator` addressing the position of the one beyond the last element in the source range to be inserted.
669669
670670
### Return value
671671
@@ -1046,7 +1046,7 @@ int compare(
10461046
int compare(
10471047
size_type position_1,
10481048
size_type number_1,
1049-
const value_type* ptr
1049+
const value_type* ptr,
10501050
size_type number_2) const;
10511051
```
10521052
@@ -1079,7 +1079,7 @@ A negative value if the operand string is less than the parameter string; zero i
10791079
10801080
### Remarks
10811081
1082-
The `compare` member functions compare either all, or part, of the parameter and operand strings depending on which in used.
1082+
The `compare` member functions compare either all, or part, of the parameter and operand strings depending on which is used.
10831083
10841084
The comparison is case-sensitive.
10851085
@@ -1778,7 +1778,7 @@ int main( )
17781778
if ( str2.begin( ) == str2.end ( ) )
17791779
cout << "The string str2 is empty." << endl;
17801780
else
1781-
cout << "The stringstr2 is not empty." << endl;
1781+
cout << "The string str2 is not empty." << endl;
17821782
}
17831783
```
17841784
@@ -2447,7 +2447,7 @@ int main( )
24472447
<< "position is: " << indexCh3b << endl << endl;
24482448
else
24492449
cout << "Elements of the substring '5G' were not "
2450-
<< "found in str3\n after the first occurrrence."
2450+
<< "found in str3\n after the first occurrence."
24512451
<< endl << endl;
24522452
24532453
// The fourth member function searches a string
@@ -3200,7 +3200,7 @@ The maximum number of characters a string could contain.
32003200

32013201
### Remarks
32023202

3203-
An exception of type [`length_error` Class](../standard-library/length-error-class.md) is thrown when an operation produces a string with a length greater than the maximum size.
3203+
An exception of type [`length_error` Class](length-error-class.md) is thrown when an operation produces a string with a length greater than the maximum size.
32043204

32053205
### Example
32063206

@@ -3479,11 +3479,11 @@ The first element of the string has an index of zero, and the following elements
34793479

34803480
`operator[]` is faster than the member function [`at`](#at) for providing read and write access to the elements of a string.
34813481

3482-
`operator[]` doesn't check whether the index passed as a parameter is valid, but the member function `at` does and so should be used in the validity isn't certain. An invalid index (an index less that zero or greater than or equal to the size of the string) passed to the member function `at` throws an [`out_of_range` Class](../standard-library/out-of-range-class.md) exception. An invalid index passed to `operator[]` results in undefined behavior, but the index equal to the length of the string is a valid index for const strings and the operator returns the null character when passed this index.
3482+
`operator[]` doesn't check whether the index passed as a parameter is valid, but the member function `at` does and so should be used if the validity isn't certain. An invalid index (an index less than zero or greater than or equal to the size of the string) passed to the member function `at` throws an [`out_of_range` Class](out-of-range-class.md) exception. An invalid index passed to `operator[]` results in undefined behavior, but the index equal to the length of the string is a valid index for const strings and the operator returns the null character when passed this index.
34833483

34843484
The reference returned may be invalidated by string reallocations or modifications for the non-`const` strings.
34853485

3486-
When compiling with [`_ITERATOR_DEBUG_LEVEL`](../standard-library/iterator-debug-level.md) set to 1 or 2, a runtime error will occur if you attempt to access an element outside the bounds of the string. For more information, see [Checked Iterators](../standard-library/checked-iterators.md).
3486+
When compiling with [`_ITERATOR_DEBUG_LEVEL`](iterator-debug-level.md) set to 1 or 2, a runtime error will occur if you attempt to access an element outside the bounds of the string. For more information, see [Checked Iterators](checked-iterators.md).
34873487

34883488
### Example
34893489

@@ -3690,7 +3690,7 @@ int main( )
36903690
if ( str2.rbegin( ) == str2.rend ( ) )
36913691
cout << "The string str2 is empty." << endl;
36923692
else
3693-
cout << "The stringstr2 is not empty." << endl;
3693+
cout << "The string str2 is not empty." << endl;
36943694
}
36953695
```
36963696
@@ -3788,7 +3788,7 @@ int main( )
37883788
if ( str2.rbegin( ) == str2.rend ( ) )
37893789
cout << "The string str2 is empty." << endl;
37903790
else
3791-
cout << "The stringstr2 is not empty." << endl;
3791+
cout << "The string str2 is not empty." << endl;
37923792
}
37933793
```
37943794
@@ -3908,10 +3908,10 @@ An iterator addressing the first character to be removed in the operand string.
39083908
An iterator addressing the last character to be removed in the operand string.
39093909
39103910
*`first`*\
3911-
An iterator, const_pointer, or const_iterator addressing the first character to be copied in the parameter string.
3911+
An iterator, `const_pointer`, or `const_iterator` addressing the first character to be copied in the parameter string.
39123912
39133913
*`last`*\
3914-
An iterator, const_pointer, or const_iterator addressing the last character to be copied in the parameter string.
3914+
An iterator, `const_pointer`, or `const_iterator` addressing the last character to be copied in the parameter string.
39153915
39163916
*`count`*\
39173917
The number of times *`char_value`* is copied into the operand string.
@@ -4151,7 +4151,7 @@ int main( )
41514151
sizerStr1 = str1.size ( );
41524152
caprStr1 = str1.capacity ( );
41534153
4154-
cout << "The string str1with augmented capacity is: "
4154+
cout << "The string str1 with augmented capacity is: "
41554155
<< str1 << endl;
41564156
cout << "The current size of string str1 is: "
41574157
<< sizerStr1 << "." << endl;
@@ -4180,7 +4180,7 @@ The original string str1 is: Hello world
41804180
The current size of original string str1 is: 11.
41814181
The capacity of original string str1 is: 15.
41824182
4183-
The string str1with augmented capacity is: Hello world
4183+
The string str1 with augmented capacity is: Hello world
41844184
The current size of string str1 is: 11.
41854185
The new capacity of string str1 is: 47.
41864186
@@ -4805,7 +4805,7 @@ For type `string`, it's equivalent to `char_traits<char>`.
48054805

48064806
### Example
48074807

4808-
See the example for [`copy`](../standard-library/char-traits-struct.md#copy) for an example of how to declare and use `traits_type`.
4808+
See the example for [`copy`](char-traits-struct.md#copy) for an example of how to declare and use `traits_type`.
48094809

48104810
## <a name="value_type"></a> `basic_string::value_type`
48114811

@@ -4847,5 +4847,5 @@ The character ch2 is: H.
48474847

48484848
## See also
48494849

4850-
[`<string>`](../standard-library/string.md)\
4851-
[Thread safety in the C++ standard library](../standard-library/thread-safety-in-the-cpp-standard-library.md)
4850+
[`<string>`](string.md)\
4851+
[Thread safety in the C++ standard library](thread-safety-in-the-cpp-standard-library.md)

0 commit comments

Comments
 (0)