C++ strcpy() Function
C++ strcpy() function copies the content of one string into another string.
If the destination string length is less than source string, entire source string does not copy into destination string.
For example, examine destination string length is 10 and source string length is 20, then only 10 characters from source string will be copied into destination string and remaining 10 characters does not copy and it will be shortened.
Syntax:
strcpy(char * destination, char * source);
Example:
#include <iostream> #include <cstring> using namespace std; int main () { char str1[30] = "Welcome to"; char str2[30] = "Onlinetpoint"; /* Copy the string str2 to str1 */ strcpy( str1, str2); cout << "Copy the string str2 to str1: "<< str1 ; return 0; }
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.