我正在使用Visual Studio Express 2012 for Windows Desktop进行开发。
我经常会遇到错误。
当我尝试构建以下内容时:
我经常会遇到错误。
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.
当我尝试构建以下内容时:
#include "stdafx.h"
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char the_string[81], *p;
cout << "Input a string to parse: ";
cin.getline(the_string, 81);
p = strtok(the_string, ",");
while (p != NULL) {
cout << p << endl;
p = strtok(NULL, ",");
}
system("PAUSE");
return 0;
}
即使我定义了_CRT_SECURE_NO_WARNINGS
,为什么还会出现此错误,如何解决?
strtok_s
?有什么问题吗? - Blacktempel#define
语句应该在任何情况下都要 先于#include "stdafx.h"
,或者放到项目属性的 C++/预处理器定义中。 - Roger Rowlandstrtok_s
- 或者使用C++函数而不是C。不要关闭警告。 - molbdnilostrtok_s
是专有库扩展,因此不具备可移植性。 - ComicSansMS