strcpy
//定义
char *strcpy(char *dest, const char *src)
//用法
char str3[] = "hellohello";//不能用char* str1,指向常量区后不可改变值
char str4[] = "worldworld";
char str5[] = "world";
cout << strcpy(str3, str4)<<endl;
cout << strcpy(str3, str5)<<endl;
//输出
worldworld
world
strncpy
//定义
char *strncpy(char *s1, const char *s2, size_t n);
//使用
char str1[] = "hellohello";//不能用char* str1,指向常量区后不可改变值
char str3[] = "hellohello";
char str2[] = "world";
strncpy(str1, str2, sizeof(str2) - 1);
strncpy(str3, str2, sizeof(str2);//这里的sizeof()输出是6个。
cout << str1 << endl;
cout << str3 << endl;
//输出
worldhello
world