//这是报错代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
char ch[20] = "character string";
const char* ch1 = "character";
char* ps;
cout << ch << "and";
cout << ch1 << endl;
cout << "Enter:";
cin >> ch;
ps = ch;
cout << ps << "!\n";
cout << "Before using strcpy():\n";
cout << ch << "at" << (int*)ps << endl;
//开辟内存
ps = new char[strlen(ch) + 1];
strcpy(ps, ch);
cout << "After using strcpy():\n";
cout << ps << "at" << (int*)ps << endl;
//释放内存
delete [] ps;
return 0;
}
编译器的错误提示
在头文件后面使用
#pragma warning( disable : 4996)
是不是就可以了
提示你用安全函数,strcpy是非安全函数
你换成strcpy_s就行了,自己百度用法,很简单