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. Java+Maven的工程运行Sonar的方式

    step 1:在maven->setting.xml中进行配置 修改mvn工程所用的setting.xml文件,在<profiles></profiles>节点中增加: ...

  2. 当 Messaging 遇上 Jepsen

    分布式系统面临的挑战 Is it better to be alive and wrong or right and dead? 随着计算机技术的发展,系统架构从集中式演进到分布式.分布式系统相对于单 ...

  3. 一个最最简单的 log4j 的 入门级使用案例

    看了比较多的文档和博客,感觉这篇博客写得比较好,比较容易懂,先 mark 一下,回头做一个记录. 文章1:http://www.cnblogs.com/rushoooooo/archive/2011/ ...

  4. vue定义自定义事件方法、事件传值及事件对象

    1.自定义事件 例如v-on:click="run" 或者 @click="run" <template> <div id="app ...

  5. 学习如何使用Markdown

    Markdown 新手指南点击查看 一级标题 二级标题 三级标题 四级标题 五级标题 六级标题 ---段落 引用 这是一个无序列表 这是一个无序列表 这是一个父无序列表 这是一个子无序列表 这是一个有 ...

  6. IHttpHandler

    https://docs.microsoft.com/en-us/dotnet/api/system.web.ihttphandler?view=netframework-4.8 Defines th ...

  7. How to pass values across the pages in ASP.net without using Session

    https://stackoverflow.com/questions/14956027/how-to-pass-values-across-the-pages-in-asp-net-without- ...

  8. 「PHP开发APP接口实战009」日常安全防范之防SQL入和XSS攻击

    防SQL注入和XSS攻击通用过滤 首先在 /app/library/ 目录下创建 Security.php 文件并添加以下代码: <?php /** * * 防SQL注入和XSS攻击通用过滤 * ...

  9. 牛客提高D4t2 卖羊驼

    分析 不难想到dp[i][j]表示前i个数分了j组的最大值 我们发现这个dp状态有决策单调性 g[i][j]表示对于第i个数它的第j位最近出现的位置 每次一定从这些点转移 预处理即可 似乎还可以做到1 ...

  10. mysql之存储过程基础篇

    1.  创建/使用数据库 mysql> create database me; mysql> use me; 2.  创建表 mysql> create table Stu(Sno ...