C++中C风格字符串的字符赋值问题,strcpy用法问题,提示错误并要求替换成strcpy_s
#include<iostream>#include<cstring>usingnamespacestd;intmain(){constchar*constStyleST...
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
const char* constStyleSTRING = "I love C++!!";
cout << "Constant string is " << constStyleSTRING << endl;
char* copy = new char[strlen(constStyleSTRING) + 1];
strcpy(copy, constStyleSTRING);
cout << "now the copy is " <<*copy << endl;
delete[]copy;
return 0;
}error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
就算我换成strcpy_s还是提示错误啊?怎么回事?
感觉真的还是C++的STL string字符串类方便很多啊!! 展开
#include <cstring>
using namespace std;
int main()
{
const char* constStyleSTRING = "I love C++!!";
cout << "Constant string is " << constStyleSTRING << endl;
char* copy = new char[strlen(constStyleSTRING) + 1];
strcpy(copy, constStyleSTRING);
cout << "now the copy is " <<*copy << endl;
delete[]copy;
return 0;
}error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
就算我换成strcpy_s还是提示错误啊?怎么回事?
感觉真的还是C++的STL string字符串类方便很多啊!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询