Strings

Suman Barik
0
#include <bits/stdc++.h>

using namespace std;

int main() {

  string str1("Hello World now");
  
  string str2(str1);
  
  string str3(5,'#');
  
  string str4(str1, 6, 6);
  
  string str5(str2.begin(), str2.begin() + 5);
  
  cout << str1 << endl << endl;
  
  cout << str2 << endl << endl;
  
  cout << str3 << endl << endl;
  
  cout << str4 << endl << endl;
  
  cout << str5 << endl << endl;
  
  string str6 = str4;
  
  int len = str6.length(); 

  cout << "Length of string is : " << len << endl << endl;
  
  char ch = str6.at(2); 

  cout << "third character of string is : " << ch << endl << endl;
  
  str6.append(" extension");
  str4.append(str6, 0, 6); 

  cout << str6 << endl << endl;
  cout << str4 << endl << endl;
  
  str6 = "This is a examples";

  str6.replace(2, 7, "ese are test");

  cout << str6 << endl;
  
  return 0;
  
}

//Output Result written below :

//Hello World now

//Hello World now

//#####

//World 

//Hello

//Length of string is : 6

//third character of string is : r

//World  extension

//World World 

//These are test examples

Post a Comment

0Comments
Post a Comment (0)