strcpy() and strncpy()

C++ inherits from C a library of functions for dealing with strings. Among the many functions provided are two for copying one string into another: strcpy() and strncpy(). strcpy() copies the entire contents of one string into a designated buffer. Listing 15.8 demonstrates its use.

Listing 15.8. Using strcpy()
 0:  // Listing 15.8 - Using strcpy()
 1:  #include <iostream>
 2:  #include <string.h>
 3:
 4:  int main()
 5:  {
 6:      char String1[] = "No man is an island";
 7:      char String2[80];
 8:
 9:      strcpy(String2,String1);
10:
11:      std::cout << "String1: " << String1 << std::endl;
12:      std::cout << "String2: " << String2 << std::endl;
13:      return 0;
14:  }
String1: No man is an island
String2: No man is an island
					

The header file STRING.H ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.