Obtain a substring. - C++ STL

C++ examples for STL:string

Description

Obtain a substring.

Demo Code

#include <iostream>
#include <string>
using namespace std;
int main()//  w  w w .j a  v  a2 s  . c  o  m
{
   string str1("Alpha");
   string str2("Beta");
   string str3("Gamma");
   string str4;
   str4 = str1 + str3;
   str4 = str4.substr(5, 4);
   cout << "str4 after being assigned str4.substr(5, 3): " << str4 << "\n\n";
   return 0;
}

Result


Related Tutorials