- string[meta header]
- std[meta namespace]
- basic_string[meta class]
- function[meta id-type]
void resize(size_type n, charT c);
void resize(size_type n);文字列の長さを変更する。
n <= max_size()
n <= size() のとき、元の文字列の先頭 n 文字をコピーした文字列で置き換える。
n > size() のとき、先頭 n 文字は元の文字列のコピー、残りは文字 c を並べた文字列で置き換える。
resize(n) は、 resize(n, charT()) と等しい。
なし
n > max_size() の時、length_error 例外を投げる。
#include <iostream>
#include <string>
int main()
{
std::string s = "hello";
// sの長さを10に変更。大きくなった場所には'x'を埋める。
s.resize(10, 'x');
std::cout << s << std::endl;
}- resize[color ff0000]
helloxxxxx