C++使用函数strcpy出现bug: 错误 C4996 'strcpy': This function or variable
C++中使用函数strcpy时出现问题:

解决方案:
在文件开头添加语句:
#pragma warning(disable:4996)
done!
剑指offer:
第一题:赋值运算符函数
#include "stdafx.h"
#include<iostream>
#include<string>
#pragma warning(disable:4996) //debug using std::cout;
using std::endl; class mystring
{
public:
mystring(char* data = nullptr);
mystring(const mystring & str);
~mystring();
mystring & operator=(const mystring & s);
void print();
private:
char* m_data;
}; mystring::mystring(char* data)
{
if (data == nullptr)
{
data = new char[];
data[] = '\0'; }
else
{
int length = strlen(data);
m_data = new char[(length + )];
strcpy(m_data, data); }
} mystring::mystring(const mystring & s)
{
int length = strlen(s.m_data);
m_data = new char[(length + )];
strcpy(m_data, s.m_data); } mystring::~mystring()
{
delete[]m_data;
} mystring & mystring::operator=(const mystring & s)
{
if (this == &s)
return *this; delete[]m_data;
m_data = nullptr; m_data = new char[strlen(s.m_data) + ];
strcpy(m_data, s.m_data); } void mystring::print()
{
cout<<("s%", m_data)<<endl; } int main() {
mystring kk = "hello";
mystring nn;
nn = kk;
kk.print();
nn.print();
system("pause");
return ;
}
C++使用函数strcpy出现bug: 错误 C4996 'strcpy': This function or variable的更多相关文章
- Visual Studio 2015 编译错误【错误 C4996 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s instead. 】的解决方案
错误提示信息: 错误 C4996 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s inst ...
- vs的【warning C4996:'fopen': This function or variable may be unsafe】解决方案
编译警告:warning C4996 与 Security Enhancements in the CRT 将过去的工程用VS2005打开的时候.你有可能会遇到一大堆的警告:warning C4996 ...
- 严重性代码说明项目文件行错误C4996'strcpy' 和Unicode 字符集选择问题
严重性代码说明项目文件 行错误 C4996 ‘strcpy’: This function or variable may be unsafe. Consider using strcpy_s ins ...
- vs2013/2015中scanf函数类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误
在使用vs2015时,遇到了scnaf函数安全性的问题,程序不能正常运行,错误如下: error C4996: 'scanf': This function or variable may be un ...
- VS 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案
在VS中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: error C4996: 'scanf': This function or variable may be uns ...
- Visual Studio 2012 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案
在VS 2012 中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: error C4996: 'scanf': This function or variable may ...
- 解决VS2015中出现类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误
用习惯了VS老版本的人当刚使用VS2013的时候可能总遇到类似于这样的错误: error C4996: 'scanf': This function or variable may be unsafe ...
- [转]Visual Studio 2012 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案
原文地址:http://www.cnblogs.com/gb2013/archive/2013/03/05/SecurityEnhancementsInTheCRT.html 在VS 2012 中编译 ...
- error C4996: 'fopen': This function or variable may be unsafe.
vs2013中错误提示信息: error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s ...
随机推荐
- tensorflow函数介绍(3)
tf.nn.softmax_cross_entropy_with_logits(logits,labels) #其中logits为神经网络最后一层输出,labels为实际的标签,该函数返回经过soft ...
- MongoDB与阿里云达成战略合作,最新数据库独家上线阿里云!
11月26日,开源数据库厂商MongoDB与阿里云在北京达成战略合作,作为合作的第一步,最新版MongoDB 4.2数据库产品正式上线阿里云平台. 目前阿里云成为全球唯一可提供最新版MongoDB服务 ...
- BZOJ 2726: [SDOI2012]任务安排 斜率优化 + 凸壳二分 + 卡精
Code: #include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) # ...
- SQL语句中 (+) 含义
(+) 表示外连接.条件关联时,一般只列出表中满足连接条件的数据.如果条件的一边出现(+),则可列出该表中在条件另一侧的数据为空的那些记录.比如两个表:员工表和工资表.员工表中有总经理.A.B.C四条 ...
- BaseActivity 基类
public abstract class BaseActivity extends AppCompatActivity implements IBaseView { private ProxyAct ...
- 服务器在没有request请求时是什么状态
服务器,例如web服务器,在没有接受到request请求时,它是一种什么状态? 是监听状态,就像电灯泡在没通电的时候,没法光,灯泡不会不停的问电线有电吗?有电吗?而是电来了,状态就发生了改变! 服务器 ...
- php面试专题---10、网络协议考点
php面试专题---10.网络协议考点 一.总结 一句话总结: 网络的考点其实就是这些:常见状态码,常见协议,osi七层模型,http和https 1.HTTP/1.1中,状态码200.301.304 ...
- 如何修改运行中的docker容器的端口映射
在docker run创建并运行容器的时候,可以通过-p指定端口映射规则.但是,我们经常会遇到刚开始忘记设置端口映射或者设置错了需要修改.当docker start运行容器后并没有提供一个-p选项或设 ...
- SQL element_at函数
库里有类似josn形式的字符串数据attr{"a":"123","b":"234"."c":&quo ...
- 腾讯开源微服务架构 Tars,高性能 RPC 开发框架
腾讯微服务架构 Tars 于今日正式开源. Tars 取名于电影“星际穿越”中的机器人,是支持多语言的高性能 RPC 开发框架和配套一体化的服务治理平台,可以帮助企业或者用户以微服务的方式快速构建稳定 ...