C++ Strings

String :-
A String is a sequence of characters. for the string class, we must include<string> in our program.
String class include functions, constructors and operators. We use these functions, constructors, operators to achieve the following task.

  • Creating string objects
  • Reading string objects from keyboard
  • Displaying string objects to the screen
  • Finding a substring from a string
  • Modifying string objects
  • Comparing string objects
  • Adding string objects
  • Obtaining the size of string
  • Accessing characters in a string.

Comparing a string with another string.

#include<iostream.h>
#include<conio.h>
#include<string.h>
int main()
{ char string1[50],string2[50];
cout<<“Enter string\n”;
cin.getline(string1,50);
cin.getline(string2,50);
if(strlen(string1)==strlen(string2))
cout<<“\nBoth string contain same value”<<“of characters”<<“\n”;
else
cout<<“\Both string contain diffrent characters”<<“of characters”<<“\n”;
getch();
return 0;
}




Follow Us

Contact Us

tutorialworldin@yahoo.com

Back to Top