Common member function
< string>
std::string::substr
string substr (size_t pos = 0, size_t len = npos) const;
Produce substring
Returns a new one
A copy of the String object that is initialized to a substring of the String object.
The
substring is the part of the object that starts at character position pos and spans len characters (or up to the end of the string, whichever comes first).
parameter
-
The position of the first character is copied as a substring.
this function returns an empty string if this is equal to the length of the string.
if this is greater than the length of the string, it will throw out_of_range.
note: the first character is represented as the value 0 (not 1).
-
The number of characters included in the subscript (if the string is short, as many characters as possible can be used as needed).
string :: non-profit value represents all characters up to the end of the string.
pos
len
size_t is an unsigned integral type (the same as member type)
string::size_type).
The return value A
String Object with a substring of this object.
Example
|
|
Output:
think live in details. |
Read More:
- Differences between length() size() and C strlen() of C + + string member functions
- C++ foundation — clear/erase/pop of string class_back
- error: unclosed character literal (How to Fix)
- In Java, int is converted to string, and zero is added before the number of bits is insufficient
- A repeated string is composed of two identical strings. For example, abcabc is a repeated string with length of 6, while abcba does not have a duplicate string. Given any string, please help Xiaoqiang find the longest repeated substring.
- 12-web security — error injection based on SQL Server — and, convert, cast
- [Warning] incompatible implicit declaration of built-in function ‘strcat’
- error: invalid use of non-static member function
- Java compareto() method
- Solve the problem of error: cannot pass objects of non trivially copyable type ‘STD:: String’ in C / C + +
- Format control of cout cout.width () and cout.fill ()
- Error in comparing the size function of STL with negative number
- Conversion from hexadecimal to decimal
- Translate() and maketrans() methods of string in Python
- The problem of strncpy and the solution of GCC compile time checking
- CIN in C + + cin.get ()、 cin.getline (), getline(), gets() function
- The differences between the equals method in the string class and the equals method in the object class
- [Two Sigma OA] Longest Chain
- vector length_error
- C++ cin.ignore Use of ()