直接使用strcpy会报错,搜过相关文章后使用strcpy_s是可以的。
按照书上使用char* strcpy(目标数组名,源数组名)也不可以。
这是为什么呢
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str1[128] = "hello";
char str2[128] = "bye";
char temp[128];
strcpy(temp, str1);
strcpy(str1, str2);
strcpy(str2, temp);
cout << str1 << endl << str2;
return 0;
}
已启动生成…
1>已启动生成: 项目: hello world, 配置: Debug x64
1>helloworld.cpp
1>D:\C++opencv_program\hello world\helloworld.cpp(10,2): 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.
1>D:\C++opencv_program\hello world\helloworld.cpp(11,2): 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.
1>D:\C++opencv_program\hello world\helloworld.cpp(12,2): 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.
1>已完成生成项目“hello world.vcxproj”的操作 - 失败。
生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个