Set the capacity of str4 to 128. - C++ STL

C++ examples for STL:string

Description

Set the capacity of str4 to 128.

Demo Code

#include <iostream>
#include <string>
using namespace std;
int main()/*w w w  .java  2 s .c  o  m*/
{
   string str1("Alpha");
   string str2("Beta");
   string str3("Gamma");
   string str4;
   str4 = str1 + str3;
   cout << "Setting the capacity of str4 to 128\n";
   str4.reserve(128);
   cout << "Capacity of str4 is now: " << str4.capacity() << "\n\n";
   return 0;
}

Result


Related Tutorials