Lab exercise programs in C plus plus
Please visit http://csprograms.in/ for more Computer Science programs.
Welcome..!!
Please visit
http://csprograms.in/
for more Computer Science programs.
Showing posts with label
string
.
Show all posts
Showing posts with label
string
.
Show all posts
Wednesday, 14 March 2012
19. C++ program to find the length of a string.
# include <iostream>
# include <string>
int main()
{
char s1[25];
cout << “Enter the string:”;
cin > > str1;
cout < < “Strlen(str1): “< < strlen(str1) < < end1;
return 0;
}
18. C++ program to convert a string into upper-case or lower-case .
# include < iostream>
# include < string>
int main()
{
char str1 [30], temp[30];
cout < < “Enter the string:”;
cin > > str1;
strcpy ( temp, str1);
cout < < “strupr ( temp ) : “ < < strupr (temp) < < end1;
cout < < “strlwr (temp) : “ < < strlwr ( temp) < < end1;
return 0;
}
17. C++ program to compare strings.
# include < iostream>
# include < string>
int main()
{
char str1[30], str2 [30];
cout << “Enter string str1:”;
cin >> str1;
cout << “Enter string str2:”;
cin >> str2;
int status = strcmp ( str1 ,str2 );
cout < < “strcmp (str1, str2 ):”;
if (status = = 0)
cout < < “str1 < <” is greater than” << str2;
else
cout < < str1 < < “is less than” << str2;
return 0;
}
16. C++ program to concatenate strings.
# include < iostream>
# include < string >
int main()
{
char str1[50], str2 [35];
cout < < “Enter string str1;”;
cin >> str1;
cout < < “Enter string str2:”;
cin >> str2;
strcat(str1,str2);
cout < < “strcat (str1, str2 ) : “< < str1;
return 0;
}
15. C++ program to copy string.
# include < iostream>
# include < string>
int main()
{
char str1[30], str [30];
cout << “Enter the string:” ;
cin >> str1;
strcpy( str2, str1);
cout << “strcpy (str2, str1) : “< < str2;
return 0;
}
14. C++ program to reverse the string .
# include < iostream>
# include < string>
int main()
{
char str1[50], str2 [50];
cout << “Enter the string:” ;
cin >> str1;
str2 = strrev ( str1);
cout << “strrev (str1) : “< < str2;
return 0;
}
Older Posts
Home
Subscribe to:
Posts (Atom)