结构功能有问题
Trouble with strcpy function
我有一个用户定义的类,其中一个成员是char*
类型。当我尝试在构造函数中初始化它时,我收到一条错误消息,指出error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead.
但是,当我将strcpy更改为strcpy_s时,它仍然会给出以下错误IntelliSense: no instance of overloaded function "strcpy_s" matches the argument list argument types are: (char *, char *)
假设Student
是类,char* name;
是数据成员之一。所以,我的构造函数是这样的:
Student (char* s = NULL) {
if (s != NULL) {
name = new char[strlen(s) + 1];
//strcpy(name,s);
strcpy_s(name,s);
}
}
这是因为strcpy_s需要一个额外的参数来指定要复制的字节数。
看这里: http://www.cplusplus.com/forum/beginner/118771/
相关文章:
- 我似乎对if/else的基本语句有问题:/
- 是否有任何C++功能可以对地图进行排序?
- 我在范围内未声明的错误类有问题
- 我的C++语言蛮力算法有问题
- 我关于函数"Assert"的C++代码有问题
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- C++类中的友元函数有问题?
- 我对数组即 0x6dfe78 有问题
- 我对 std::unique(算法)C++有问题
- 使用 fstream 库并在屏幕上打印的文件有问题?
- 这个模板为什么有问题?如何正确编译
- 我对 MyGraph 属性顶点名称和边权重有问题
- delete[]有问题,如何部分删除内存
- 我有模板功能.通过使用函数std::for_each,用这个容器中的最大数字替换每个正数
- 在C++中使用exit()退出程序有问题吗
- 我的显示功能有问题
- 二叉搜索树在插入功能方面有问题
- 有问题使循环工作与功能相结合
- 结构功能有问题
- 无效功能有问题