String Functions In C++
String Functions In C++
It has 7 types
1. string concatenation
2. string comparision
3. string copy
4. string length
5. string reverse
5. string upper
6. string lower
String concatenation
#include<iostream.h>
#include<conioh.>
#include<string.h>
void main()
{
char string1 [20];
char string2 [20];
clrscr();
cout<<"Enter the string 1 is:"<<endl;
cin>>string1;
cout<<"Enter the string2 is:"<<endl;
cin>>string2;
strcat(string1,string2);
cout<<"The given string1 is:"<<string1<<endl;
getch();
}
String compare
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int x;
char string1 [20];
char string2 [20];
clrscr();
cout<<"Enter the string1 is:"<<endl;
cin>>string1;
cout<<"Enter the string2 is:"<<endl;
cin>>string2;
x=strcmp(string1,string2);
if(x==0)
cout<<"The given name is same"<<endl;
else
cout<<"The given name is different"<<endl;
getch();
}
String copy
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int x;
char string1[20];
char string2[20];
clrscr();
cout<<"Enter the string1 is:"<<endl;
cin>>string1;
cout<<"Enter the string2 is:"<<endl;
cin>>string2;
strcpy(string1,string2);
cout<<"The given string1 is:"<<string1<<endl;
cout<<"The given string2 is:"<<string2<<endl;
getch();
}
String length
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int n1,n2;
char string1 [20];
char string2 [20];
clrscr();
cout<<"Enter the string 1 is:"<<endl;
cin>>string1;
cout<<"Enter the string2 is:"<<endl;
cin>>string2;
n1=strlen(string1);
n2=strlen(string2);
cout<<"The given length of the string1 is"<<n1<<endl;
cout<<"The given length of the string2 is"<<n2<<endl;
getch();
}
String without int
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char string1 [20];
char string2 [20];
clrscr();
cout<<"Enter the string1 is:"<<endl;
cin>>string1;
cout<<"Enter the string2 is:"<<endl;
cin>>string2;
cout<<"The given length of string1 is "<<strlen(string1)<<endl;
cout<<"The given length of string2 is"<<strlen(string2)<<endl;
getch();
}
String reverse
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char string1 [20];
char string2 [20];
clrscr();
cout<<"Enter the string1 is:"<<endl;
cin>>string1;
cout<<"Enter the string2 is:"<<endl;
cin>>string2;
strrev(string1);
strrev(string2);
cout<<"The given reverse of the string1 is "<<string1<<endl;
cout<<"The given reverse of the string2 is"<<string2<<endl;
getch();
}
String upper, lower
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char string1 [20];
char string2 [20];
clrscr();
cout<<"Enter the string1 is"<<endl;
cin>>string1;
cout<<"Enter the string2 is:"<<endl;
cin>>String2;
strupr(string1);
strlwr(string2);
cout<<"The given reverse of the string1 is<<string1<<endl;
cout<<"The given reverse of the string2 is<<string2<<endl;
getch();
}
0 Comments