C++ String Library - resize



Description

It resizes the string to a length of n characters.

Declaration

Following is the declaration for std::string::resize.

void resize (size_t n);

C++11

void resize (size_t n, char c);

Parameters

  • n − It is a new string length.

  • c − Character used to fill the new character space added to the string.

Return Value

none

Exceptions

if an exception is thrown, there are no changes in the string.

Example

In below example for std::string::resize.

#include <iostream>
#include <string>

int main () {
   std::string str ("Sairamkrishna Mammahe");
   std::cout << str << '\n';

   unsigned sz = str.size();

   str.resize (sz+2,'+');
   std::cout << str << '\n';

   str.resize (14);
   std::cout << str << '\n';
   return 0;
}

The sample output should be like this −

Sairamkrishna Mammahe
Sairamkrishna Mammahe++
Sairamkrishna 
string.htm
Advertisements
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy