Skip to content

Commit 6c77df9

Browse files
committed
Merge branch 'master' of https://github.com/MicrosoftDocs/cpp-docs-pr into 1769497-fix-build-validation-issues-09-10
2 parents ec35708 + 5fadc49 commit 6c77df9

File tree

10 files changed

+289
-36
lines changed

10 files changed

+289
-36
lines changed

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

Lines changed: 127 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
title: "basic_string Class"
3-
ms.date: "11/12/2019"
4-
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::swap"]
5-
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++], substr", "std::basic_string [C++], swap"]
3+
description: "API reference for the `basic_string` class, which is the Standard C++ string class."
4+
ms.date: "9/10/2020"
5+
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"]
6+
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"]
67
ms.assetid: a9c3e0a2-39bf-4c8a-b093-9abe30839591
78
---
89
# basic_string Class
@@ -74,6 +75,7 @@ The type that represents the stored allocator object that encapsulates details a
7475
|[data](#data)|Converts the contents of a string into an array of characters.|
7576
|[empty](#empty)|Tests whether the string contains characters.|
7677
|[end](#end)|Returns an iterator that addresses the location succeeding the last element in a string.|
78+
|[ends_with](#ends_with)<sup>C++20</sup>|Checks whether the string ends with the specified suffix.|
7779
|[erase](#erase)|Removes an element or a range of elements in a string from a specified position.|
7880
|[find](#find)|Searches a string in a forward direction for the first occurrence of a substring that matches a specified sequence of characters.|
7981
|[find_first_not_of](#find_first_not_of)|Searches through a string for the first character that isn't any element of a specified string.|
@@ -95,6 +97,7 @@ The type that represents the stored allocator object that encapsulates details a
9597
|[rfind](#rfind)|Searches a string in a backward direction for the first occurrence of a substring that matches a specified sequence of characters.|
9698
|[shrink_to_fit](#shrink_to_fit)|Discards the excess capacity of the string.|
9799
|[size](#size)|Returns the current number of elements in a string.|
100+
|[starts_with](#starts_with)<sup>C++20</sup>|Checks whether the string starts with the specified prefix.|
98101
|[substr](#substr)|Copies a substring of at most some number of characters from a string beginning from a specified position.|
99102
|[swap](#swap)|Exchange the contents of two strings.|
100103
@@ -1753,7 +1756,7 @@ int main( )
17531756
cout << endl;
17541757

17551758
// The dereferenced iterator can be used to modify a character
1756-
*str1_Iter = 'T';
1759+
*str1_Iter = 'T';
17571760
cout << "The last character-letter of the modified str1 is now: "
17581761
<< *str1_Iter << endl;
17591762
cout << "The modified string str1 is now: " << str1 << endl;
@@ -1778,6 +1781,66 @@ The modified string str1 is now: No way ouT.
17781781
The string str2 is empty.
17791782
```
17801783

1784+
## <a name="ends_with"></a> basic_string::ends_with
1785+
1786+
Check whether the string ends with the specified suffix.
1787+
1788+
```cpp
1789+
bool ends_with(const CharType c) const noexcept;
1790+
bool ends_with(const CharType* const x) const noexcept;
1791+
bool ends_with(const basic_string_view sv) const noexcept;
1792+
```
1793+
1794+
### Parameters
1795+
1796+
*c*\
1797+
The single character suffix to look for.
1798+
1799+
*sv*\
1800+
A string view containing the suffix to look for.\
1801+
You can pass a `std::basic_string`, which converts to a string view.
1802+
1803+
*x*\
1804+
Null-terminated character string containing the suffix to look for.
1805+
1806+
### Return Value
1807+
1808+
`true` if the string ends with the specified suffix; `false` otherwise.
1809+
1810+
### Remarks
1811+
1812+
`ends_with()` is new in C++20. To use it, specify the [/std:c++latest](../build/reference/std-specify-language-standard-version.md) compiler option.
1813+
1814+
See [starts_with](#starts_with) to check if a string starts with the specified prefix.
1815+
1816+
### Example
1817+
1818+
```cpp
1819+
// Requires /std:c++latest
1820+
#include <string>
1821+
#include <iostream>
1822+
1823+
int main()
1824+
{
1825+
std::basic_string<char> str = "abcdefg";
1826+
1827+
std::cout << std::boolalpha; // so booleans show as 'true'/'false'
1828+
std::cout << str.ends_with('g') << '\n';
1829+
std::cout << str.ends_with("eFg") << '\n';
1830+
1831+
std::basic_string<char> str2 = "efg";
1832+
std::cout << str.ends_with(str2);
1833+
1834+
return 0;
1835+
}
1836+
```
1837+
1838+
```Output
1839+
true
1840+
false
1841+
true
1842+
```
1843+
17811844
## <a name="erase"></a> basic_string::erase
17821845

17831846
Removes an element or a range of elements in a string from a specified position.
@@ -4539,6 +4602,66 @@ The current size of string str1 is: 11.
45394602
The capacity of string str1 is: 15.
45404603
```
45414604

4605+
## <a name="starts_with"></a> basic_string::starts_with
4606+
4607+
Check whether the string starts with the specified prefix.
4608+
4609+
```cpp
4610+
bool starts_with(const CharType c) const noexcept;
4611+
bool starts_with(const CharType* const x) const noexcept;
4612+
bool starts_with(const basic_string_view sv) const noexcept;
4613+
```
4614+
4615+
### Parameters
4616+
4617+
*c*\
4618+
The single character prefix to look for.
4619+
4620+
*sv*\
4621+
A string view containing the prefix to look for.\
4622+
You can pass a `std::basic_string`, which converts to a string view.
4623+
4624+
*x*\
4625+
Null-terminated character string containing the prefix to look for.
4626+
4627+
### Return Value
4628+
4629+
`true` if the string starts with the specified prefix; `false` otherwise.
4630+
4631+
### Remarks
4632+
4633+
`starts_with()` is new in C++20. To use it, specify the [/std:c++latest](../build/reference/std-specify-language-standard-version.md) compiler option.
4634+
4635+
See [ends_with](#ends_with) to see if a string ends with the specified suffix.
4636+
4637+
### Example
4638+
4639+
```cpp
4640+
// Requires /std:c++latest
4641+
#include <string>
4642+
#include <iostream>
4643+
4644+
int main()
4645+
{
4646+
std::basic_string<char> str = "abcdefg";
4647+
4648+
std::cout << std::boolalpha; // so booleans show as 'true'/'false'
4649+
std::cout << str.starts_with('b') << '\n';
4650+
std::cout << str.starts_with("aBc") << '\n';
4651+
4652+
std::basic_string<char> str2 = "abc";
4653+
std::cout << str.starts_with(str2);
4654+
4655+
return 0;
4656+
}
4657+
```
4658+
4659+
```Output
4660+
false
4661+
false
4662+
true
4663+
```
4664+
45424665
## <a name="substr"></a> basic_string::substr
45434666

45444667
Copies a substring of at most some number of characters from a string beginning from a specified position.

0 commit comments

Comments
 (0)