Visual Studio 2017 免费版提示strcpy()函数问题
来源:互联网 发布:win7新增打印机usb端口 编辑:程序博客网 时间:2024/06/06 00:56
编译器提示要使用更安全的strcpy_s()函数,函数使用方法如下
格式:strcpy_s(pn, strlen(temp) + 1, temp);
temp:要复制的原字符串
strlen(temp) + 1:字符串长度。切记加一,存放结束符‘\0’
pn:要将temp复制到的位置
以下为C++ primer plus 例程中需要改动的(第四章)
// delete.cpp -- using the delete operator#include <iostream>#include <cstring> // or string.husing namespace std;char * getname(void); // function prototypeint main(){//char * name; // create pointer but no storag//name = getname(); // assign address of string to namechar * name = getname();cout << name << " at " << (int *)name << "\n";delete[] name; // memory freedname = getname(); // reuse freed memorycout << name << " at " << (int *)name << "\n";delete[] name; // memory freed again // cin.get(); // cin.get();return 0;}char * getname() // return pointer to new string{char temp[80]; // temporary storagecout << "Enter last name: ";cin >> temp;char * pn = new char[strlen(temp) + 1];//strcpy(pn, temp); // copy string into smaller spacestrcpy_s(pn, strlen(temp) + 1, temp);return pn; // temp lost when function ends}
阅读全文
0 0
- Visual Studio 2017 免费版提示strcpy()函数问题
- Visual Studio 2013中strcpy函数报错
- visual studio 2008 提示 “函数xxx 已有主体”
- 使用"Visual Studio命令提示"查看cad中的重整函数
- 关于Visual Studio 2013中strcpy函数的使用报错
- visual studio 2017 问题记录
- Visual Studio.net 2003安装提示重启问题
- Visual Studio.net 2003安装提示重启问题
- Visual Studio.net 2003安装提示重启问题
- Visual Studio.net 2003安装提示重启问题
- Visual Studio.net 2003安装提示重启问题
- 解决 Visual Studio 2010 无HTML和Javascript提示问题
- Visual Studio初始化解决智能提示等问题
- Visual Studio 2008 每日提示
- visual studio技巧每日提示
- Visual Studio 2008 每日提示
- Visual Studio安装Visual Assist后中文注释提示错误问题
- Visual studio 2017中 Javascript无法智能提示的解决办法
- 简单视频播放AVPlayer和AVPlayerViewController
- 《程序员的思维修炼:开发认知潜能的九堂课》【PDF】下载
- 报错ora-04098:触发器无效且未通过重新验证
- SVG
- unity中Instantiate后物体不能显示或者显示非常大的原理及解决方法
- Visual Studio 2017 免费版提示strcpy()函数问题
- 客户端接收服务端消息推送sockjs-client的使用
- 调戏木马病毒的正确姿势-基础篇
- 点击页面上的一个按钮时,如何触发controller中的方法
- date对象常用方法
- C#的银行家算法的实现
- SpannableStringBuilder导致ellipsize失效(两者冲突)
- 移动端根据屏幕大小自动设置body字体大小
- 动态规划之零件加工