public member function
<string>
std::basic_string::resizevoid resize (size_type n);void resize (size_type n, charT c);
Resize string
Resizes the string to a length of n characters.If n is smaller than the current string length, the current value is shortened to its first n character, removing the characters beyond the nth.
If n is greater than the current string length, the current content is extended by inserting at the end as many characters as needed to reach a size of n. If c is specified, the new elements are initialized as copies of c, otherwise, they are value-initialized characters (null characters).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// resizing string
#include <iostream>
#include <string>
int main ()
{
std::string str ("I like to code in C");
std::cout << str << '\n';
std::string::size_type sz = str.size();
str.resize (sz+2,'+');
std::cout << str << '\n';
str.resize (14);
std::cout << str << '\n';
return 0;
}
I like to code in C I like to code in C++ I like to code
If n is greater than max_size, a length_error exception is thrown.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4