头文件< cstring >
语法
char* strcpy( char* dest, const char* src );
解释
demo
// strcpy char *s1 = "1234"; char s2[3] = {0}; strcpy(s2, s1); std::cout << "s1: " << s1 << std::endl; std::cout << "s2: " << s2 << std::endl;
头文件< cstring >
语法
char *strncpy( char *dest, const char *src, std::size_t count );
解释
demo
// strncpy char *s1 = "1234"; char s2[10] = {0}; strncpy(s2, s1, 5); std::cout << "s1: " << s1 << std::endl; std::cout << "s2: " << s2 << std::endl;
头文件< cstring >
语法
void* memcpy( void* dest, const void* src, std::size_t count );
解释
demo
// memcpy char *s1 = "1234"; char s2[10] = {0}; memcpy(s2, s1, 5); std::cout << "s1: " << s1 << std::endl; std::cout << "s2: " << s2 << std::endl;