Coding with C Plus Plus
▼
Tuesday, 30 June 2015
Monday, 29 June 2015
Reversal of string
Lets play a game !!!!
Write your name in reverse order.
Ok wait,let me write my name first.
Khawaja
Reversed: ajawahK
Isn't it interesting?
So,today I am here with an interesting program that will input a string from the user and then display its reverse.
Have a look at its source code.
Source code
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
main()
{
char abc[20];
cout<<"Enter any string:";
gets(abc);
int len=strlen(abc); //used to find the string length
for(int i=len-1;i>=0;i--) //reverse loop
cout<<abc[i];
return 0;
getch();
}
Output

Reversal of string

Saturday, 27 June 2015
Friday, 26 June 2015
String characteristics
In my previous blog, I have given you an introduction to strings.Today I will discuss on some string characteristics or you can say,"string operations".
String length( )
String size( )
If you want to find the length of any string, then its syntax is as follows:
str.length( );
String length( )
If you want to find the length of any string, then its syntax is as follows:
str.length( );
String capacity( )
If you want to find the capacity of any string, then its syntax is as follows:
str.capacity( );
Maximum size( )
If you want to size the maximum size of any string, then its syntax is as follows:
str.max_size( );
String empty or not
If you want to check whether the string is empty or not,then its syntax is as follows:
(str.empty?"yes":"no") ; (it is same as conditional operator)
So, to implementation of these operations is as follows:
Source code
#include<iostream>
#include<string.h>
using namespace std;
main()
{
string s1;
cout<<"Enter any string:";
getline(cin,s1); // syntax for getting the input of string
cout<<"Size="<<s1.size()<<endl<<endl;
cout<<"Length="<<s1.length()<<endl<<endl;
cout<<"Capacity="<<s1.capacity()<<endl<<endl;
cout<<"Maximum size="<<s1.max_size()<<endl<<endl;
cout<<"Empty="<<(s1.empty()?"yes":"no")<<endl<<endl;
}