prowessapps.in String Handling Programs in C++

#include<iostream>
using namespace std;
int main() {
 string name;
 cout<<"Enter a string : ";
 getline(cin,name);
 int len = name.length();
 cout<<"Length = "<< len<< endl;
 return 0;
}
OUTPUT
Enter a string : cprowess
Length = 8

#include<iostream>
using namespace std;
int main() {
 string s1,s2;
 cout<<"Enter a string : ";
 getline(cin,s1);
 s2 = s1;
 cout<<"Copied String : "<< s2;
 return 0;
}
OUTPUT
Enter a string : cprowess
Copied String : cprowess

#include<iostream>
using namespace std;
int main() {
 string s1,s2,s3;
 cout<<"Enter 1st string : ";
 getline(cin,s1);
 cout<<"Enter 2nd string : ";
 getline(cin,s2);
 s3 = s1+s2;
 cout<<"Concatenate String : "<< s3;
 return 0;
}
OUTPUT
Enter 1st string : c++
Enter 2nd string : is awesome
Concatenate String : c++ is awesome

#include<iostream>
using namespace std;
int main() {
 string s1;
 int count =0;
 cout<<"Enter a string : ";
 getline(cin,s1);
 for(int i = 0; i< s1.length(); i++) {
  char x = s1.at(i);
  if(x=='A' ||x=='E'||x=='I'||x=='O'
  ||x=='U'||x=='a'||x=='e'||x=='i'
  ||x=='o'||x=='u') {
 count++;
  }
 }
 cout<<"Vowels = "<< count<< endl;
 return 0;
}
OUTPUT
Enter a string : cprowess
Vowels = 2

#include<iostream>
using namespace std;
int main() {
 string s1,s2;
 cout<<"Enter 1st string : ";
 getline(cin,s1);
 cout<<"Enter 2nd string : ";
 getline(cin,s2);
 if(s1==s2) {
  cout<<"Strings are equals ";
 }
 else {
  cout<<"Strings are unequals ";
 }
 return 0;
}
OUTPUT
Enter 1st string : cprowess
Enter 2nd string : c++prowess
strings are unequal

#include<iostream>
#include<algorithm>
using namespace std;
int main() {
 string s1;
 cout<<"Enter a string : ";
 getline(cin,s1);
 reverse(s1.begin(),s1.end());
 cout<<"Reverse String = "<< s1;
 return 0;
}

OUTPUT
Enter a string : cprowess
Reverse String = sseworpw

#include<iostream>
#include<algorithm>
using namespace std;
int main() {
 string s1,s2;
 cout<<"Enter a string : ";
 getline(cin,s1);
 s2 = s1;
 reverse(s1.begin(),s1.end());
 if(s1==s2) {
  cout<<"String is Palindrome";
 }
 else {
  cout<<"String is not Palindrome";
 }
 return 0;
}
OUTPUT
Enter a string : cprowess
String is not Palindrome

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main() {
 string s1;
 cout<<"Enter a string : ";
 getline(cin,s1);
 for(int i = 0; i< s1.length(); i++) {
  if(s1[i]>=97 && s1[i]<=122) {
   s1[i] = s1[i]-32;
  }
  cout<<"In Upper case: "<< s1[i];
 }
 return 0;
}
OUTPUT
Enter a string : cproWess
 In Upper case: CPROWESS


Get it on Google Play


CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017, prowessapps.in, All rights reserved