C++ Program to Copy String

« Previous Program Next Program »

Copy String in C++

To copy string in C++ programming, you have to ask to the user to enter the string to make copy to another variable say str2 of same type using function strcpy() and display the copied string on the output screen as shown here in the following program.

C++ Programming Code to Copy String

Following C++ program ask to the user to enter the string to copy it into another string, then display the copied string on the screen :

/* C++ Program - Copy String */
void main()
	char str1[20], str2[20];
	cout<<"Enter a string : ";
	cout<<"copying string 1 into string 2 ......\n";
	strcpy(str2, str1);
	cout<<"String 2 after copying "<<str2;

When the above C++ program is compile and executed, it will produce the following result:

C++ program copy string

Same Program in Other Language

You may like the same program in other programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test