Copy a string using strcpy() function - C++ Data Type

C++ examples for Data Type:char array

Description

Copy a string using strcpy() function

Demo Code

#include <iostream>
#include <cstring>                     //for strcpy()
using namespace std;
int main()// ww  w.  jav a 2 s .c o  m
{
   char str1[] = "this is a test this is atest";
   const int MAX = 80;                 //size of str2 buffer
   char str2[MAX];                     //empty string
   strcpy(str2, str1);                 //copy str1 to str2
   cout << str2 << endl;               //display str2
   return 0;
}

Result


Related Tutorials