HOW TO SWAP TO STRINGS IN C++

Category:

//PROGRAM TO SWAP TO STRINGS IN C++
#include < iostream >
#include < iomanip >
using namespace std;
void main()
{
//Assigning two strings directly to the char arrays
 char x[10]="emmaneale",y[10]="mendu",temp[10];
 cout << "Given first Number FirstName = " << x;
 cout << endl << "Given Second Number LastName = " << y;
 //copying x to temp using string copy
 strcpy(temp,x);
strcpy(x,y);
 strcpy(y,temp);
 cout << endl << "Strings swapped";
 cout << endl << "After Swapping to given strings Result is FirstName= "<< x<< " and" << endl;
 cout << "LastName= " << y << endl;
 system("pause");
}

Comments (0)

Post a Comment