求教这段关于strtok的代码在vs2012中运行报错

cktaa 2014-05-02 06:48:23
#include <string.h>
#include <stdio.h>

int main()
{
char s[] = "Golden Global View,disk * desk";
const char *d = " ,*";
char *p;
p = strtok(s,d);
while(p)
{
printf("%s\n",p);
p=strtok(NULL,d);
}

return 0;
}
1>ConsoleApplication1.cpp(15): error C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\string.h(200) : see declaration of 'strtok'
...全文
503 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-11-05
  • 打赏
  • 举报
回复
引用 3 楼 buyong 的回复:
#pragma warning (disable : 4996)
英雄所见略同。
花草蒙拾 2014-11-05
  • 打赏
  • 举报
回复
右击工程 - 属性 - 配置属性 - C/C++ - 命令行 命令行增加 /D _CRT_SECURE_NO_WARNINGS 这个才是正确的
花草蒙拾 2014-11-05
  • 打赏
  • 举报
回复
用strtok_s来替代它,然后在括号里加上Null,p = strtok_s(s,d,NULL); p=strtok(NULL,d,NULL); 应该是这样的,我试了可以
buyong 2014-05-06
  • 打赏
  • 举报
回复
#pragma warning (disable : 4996)
cktaa 2014-05-03
  • 打赏
  • 举报
回复
studio 2012 取消了strtok?strtok_s网络上的例程也不能用呀,可以提供一个能用的例子吗?
图灵狗 2014-05-02
  • 打赏
  • 举报
回复
它的提示已经非常清楚,strtok是不安全的,改用strtok_s来替代它。
引用 楼主 cktaa 的回复:
#include <string.h> #include <stdio.h> int main() { char s[] = "Golden Global View,disk * desk"; const char *d = " ,*"; char *p; p = strtok(s,d); while(p) { printf("%s\n",p); p=strtok(NULL,d); } return 0; } 1>ConsoleApplication1.cpp(15): error C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\string.h(200) : see declaration of 'strtok'

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧