📄 str_cpy1.cpp
字号:
//str_cpy1.cpp
#include <iostream.h> //cin,cout
#include <conio.h> //getch()
#include <string.h>
void main()
{ char *source="America apologize!",*destination;
int len;
len = strlen(source)+1; //取得字符串长度加1
destination = new char[len]; //配置内存
strcpy(destination,source); //拷贝字符串
cout << "用strcpy()全部拷贝后字符串为:"
<< destination << endl;
strcpy(destination,""); //清除字符串
cout << "用strcpy()清除字符串后:"
<< destination << endl;
stpcpy(destination,source); //拷贝字符串
cout << "用stpcpy()全部拷贝后字符串为:"
<< destination << endl;
stpcpy(destination,""); //清除字符串
cout << "用stpcpy()清除字符串后:"
<< destination << endl;
strncpy(destination,source,7); //拷贝部分字符串
destination[7]='\0'; //加上结尾
cout << "用strncpy()拷贝部分后字符串为:"
<< destination << endl;
destination[0]='\0';
cout << "用\\0清除字符串后:"
<< destination << endl;
delete[] destination;
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -