Obtain a substring : string substr « String « C++






Obtain a substring

  
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string str1("this is a test");

  cout << "  str1: " << str1 << endl;

  // Obtain a substring.
  str1 = str1.substr(5, 4);
  cout << str1 << "\n\n";


  return 0;
}
  
    
  








Related examples in the same category

1.string member function substr
2.substr 'to-end-of-string' option
3.Split file name in command line into base name and extension
4.Find substring day in a string and check if it was found