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的更多相关文章

  1. 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 ...

  2. vs的【warning C4996:'fopen': This function or variable may be unsafe】解决方案

    编译警告:warning C4996 与 Security Enhancements in the CRT 将过去的工程用VS2005打开的时候.你有可能会遇到一大堆的警告:warning C4996 ...

  3. 严重性代码说明项目文件行错误C4996'strcpy' 和Unicode 字符集选择问题

    严重性代码说明项目文件 行错误 C4996 ‘strcpy’: This function or variable may be unsafe. Consider using strcpy_s ins ...

  4. 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 ...

  5. VS 编译错误【error C4996: 'scanf': This function or variable may be unsafe. 】的解决方案

    在VS中编译 C 语言项目,如果使用了 scanf 函数,编译时便会提示如下错误: error C4996: 'scanf': This function or variable may be uns ...

  6. 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 ...

  7. 解决VS2015中出现类似于error C4996: 'scanf': This function or variable may be unsafe的安全检查错误

    用习惯了VS老版本的人当刚使用VS2013的时候可能总遇到类似于这样的错误: error C4996: 'scanf': This function or variable may be unsafe ...

  8. [转]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 中编译 ...

  9. 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 ...

随机推荐

  1. 前端VUE环境构建

    https://nodejs.org/en/ 安装node 安装淘宝npm镜像 D:\>cd cnpm D:\cnpm>npm install -g cnpm --registry=htt ...

  2. django 使用ORM插入数据,提示Cannot assign "1": "B" must be a "Projectconfig" instance.

    这是因为使用了外键导致的, 如果使用了外键,先实例化外键查询,然后再插入的表里面放入实例化后的外键连接

  3. 阿里云Kubernetes服务 - Service Broker快速入门指南

    4月底阿里云容器服务上线了基于Kubernetes集群的服务目录功能.阿里云的容器的服务目录遵循Open Service Broker API标准,提供了一系列的服务代理组件,实现了对主流开源服务如M ...

  4. Django2 --- cookie

    1. 什么是cookie ?用途是什么? Cookies是一些存储在用户电脑上的小文件.它是被设计用来保存一些站点的用户数据,这样能够让服务器为这样的用户定制内容,后者页面代码能够获取到Cookie值 ...

  5. 包装CGFloat和用NSNumber初始化的区别?

    @(CGFloat)和[NSNumber numberWith:CGFloat]的区别?

  6. U盘安装win8(win7)+centos7双系统

    centos7除了之后,就像尝鲜看看,但是发现安装之后会失去win8启动项.导致重装系统,经过反复折腾,终于搞定了,发出来共享下.默认你的 window系统已经安装好,不介绍window安装过程.本文 ...

  7. 理解性能的奥秘——应用程序中慢,SSMS中快(4)收集解决参数嗅探问题的信息

    ---从计划缓存中直接获取查询计划和参数: ), ) SELECT @dbname = 'hydee_连锁', @procname = 'dbo.p_select_ware'; WITH baseda ...

  8. 第二周训练 | 搜索技术 4.3 BFS

    A - Red and Black There is a rectangular room, covered with square tiles. Each tile is colored eithe ...

  9. 【运维】使用FileZilla搭建FTP服务器

    一.下载Filezilla  Server 官网网址:https://filezilla-project.org 二.安装Filezilla  Server   Filezilla  Server的安 ...

  10. CSS页面乱码 GB2312、UTF-8格式问题解决方案

      如同左图所现,出现了页面乱码问题本来应该是显示gb3212字符的"关闭"文字了.. 解决方案一: 在所调用的CSS页面的第一行添加下边的这一句代码, 注意:一定要是在CSS的头 ...