for length:-
#include <iostream>
- using namespace std;
int main()
{
string str = "C++ Programming";
// you can also use str.length()
cout << "String Length = " << str.size();
return 0;
}
- for copy:-
- #include <iostream>
- using namespace std;
- int main()
- {
- string s1, s2;
- cout << "Enter string s1: ";
- getline (cin, s1);
- s2 = s1;
- cout << "s1 = "<< s1 << endl;
- cout << "s2 = "<< s2;
- return 0;
- }
- for compare:-
#include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> void main() { clrscr(); char str1[100], str2[100]; cout<<"Enter first string : "; gets(str1); cout<<"Enter second string : "; gets(str2); if(strcmp(str1, str2)==0) { cout<<"Both the strings are equal"; } else { cout<<"Both the strings are not equal"; } getch(); }
for concat:-
#include <iostream>
using namespace std;
int main()
{
string s1, s2, result;
cout << "Enter string s1: ";
getline (cin, s1);
cout << "Enter string s2: ";
getline (cin, s2);
result = s1 + s2;
cout << "Resultant String = "<< result;
return 0;
}
for palindrome:-
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char str1[20], str2[20];
int i, j, len = 0, flag = 0;
cout << "Enter the string : ";
gets(str1);
len = strlen(str1) - 1;
for (i = len, j = 0; i >= 0 ; i--, j++)
str2[j] = str1[i];
if (strcmp(str1, str2))
flag = 1;
if (flag == 1)
cout << str1 << " is not a palindrome";
else
cout << str1 << " is a palindrome";
return 0;
}
- note:-it's just a sudo code if its not executing on your device make some changes in the further code this is only for understanding logic.thankyou for visiting us stay tuned for learning and more intresting u can ask questions in comment section check other blogs for more info. comment mail for compitative cading thankyou.👍😎🙏
0 Comments