Tuesday, August 15, 2017

C++ String class - functions.

This C++ program will demonstrate use of String class - functions. #include <iostream>
#include <string>

using namespace std;

int main () {
   int  len;
   string str1="Hello", str2="World", str;
   
   //String copy function: str1 into str
   str = str1;
   cout << "Content in str = "<< str <<endl;

   //String concatenate: str1 and str2
   str = str1 + str2;
   cout << "Content in str = "<< str <<endl;

   //Total lenghth of str1 after strcat()
   len = str.size();
   cout << "Length of str: " << len <<endl;

   return 0;
}

Output of program 

Content in str = Hello
Content in str = HelloWorld
Length of str: 10

No comments:

Post a Comment