C++ Laguage



Admission Enquiry Form

  

String Data Type in C++


String Data Type in C++:

Program of String Data Type in C++

//string data type in C++
#include<iostream>
using namespace std;
int main()
{
string str;
str="compuhelp";
cout<<str;
//cout<<"hello";
cout<<"\n"<<str.length();//function to find length of string
cout<<"\n"<<str.at(2);//function to return character at location 2 which is 'm'
cout<<"\n"<<str.substr(5,4);//will return help from the string
cout<<"\n"<<str.substr(5);//will return help
cout<<"\n"<<str.find("h");//will return position of 'h' in the string 5
cout<<"\n"<<str.find("c");//will return 0
str="INDIA";
cout<<endl<<str.find_last_of("I");//will return 3
cout<<endl<<str;
cout<<endl<<str.insert(3,"test");//will insert test at location 3
cout<<endl<<str;
return 0;

}

//end of main