C++ string Create string object in various ways

Description

C++ string Create string object in various ways

#include <iostream>
#include <string>
using namespace std;
int main()/*w w  w  .ja va2 s.c o m*/
{
   string str1;  // an empty string
   string str2("this is a test");
   string str3 = "test test test";
   string str4(str3);
   string str5(str4, 4);
   string str6 = "linear";
   string str7(str6, 3, 3);
   cout << "str1 is: " << str1 << endl;
   cout << "str2 is: " << str2 << endl;
   cout << "str3 is: " << str3 << endl;
   cout << "str4 is: " << str4 << endl;
   cout << "str5 is: " << str5 << endl;
   cout << "str6 is: " << str6 << endl;
   cout << "str7 is: " << str7 << endl;
   return 0;
}



PreviousNext

Related