在VS2015中按參考代碼編譯時出現(xiàn)的問題
嚴(yán)重性 代碼 說明 項目 文件 行 禁止顯示狀態(tài)
錯誤 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. ConsoleApplication5 i:\vs2015project\consoleapplication5\consoleapplication5\test.cpp 9
2016-08-30
#include <string.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
#pragma warning(disable:4996)
int main(void)
{
//在堆中申請100個char類型的內(nèi)存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內(nèi)存中
strcpy(str, "Hello imooc");
//打印字符串
cout << str << endl;
//釋放內(nèi)存
delete[]str;
str = NULL;
system("pause");
return 0;
}
注意:新加了一行#pragma warning(disable:4996)
2016-05-30
你加二句
#include <stdlib.h>
system("pause");
#include <string.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
//在堆中申請100個char類型的內(nèi)存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內(nèi)存中
strcpy(str, "Hello imooc");
//打印字符串
cout << str << endl;
//釋放內(nèi)存
delete[]str;
str = NULL;
system("pause");
return 0;
}
2016-05-09
#include <string.h>
#include <iostream>
using namespace std;
int main(void)
{
//在堆中申請100個char類型的內(nèi)存
char *str = new char[100];
//拷貝Hello C++字符串到分配的堆中的內(nèi)存中
strcpy(str, "Hello imooc");
//打印字符串
cout << str << endl;
//釋放內(nèi)存
delete[]str;
str = NULL;
return 0;
}