I am using Visual Studio Express 2012 for Windows Desktop.
I always get error
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.
When I try to build the following:
#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;
}
Why am I getting this error even though I define _CRT_SECURE_NO_WARNINGS
, and how do I fix it?
strtok_s
? What's the problem ? – Carolincarolina#define
should in any case be before#include "stdafx.h"
or alternatively put it in your project properties under C++/Preprocessor definitions. – Forzandostrtok_s
instead, as suggested - or use C++ functions instead of C. Do not switch off warnings. – Harrisharrisburgstrtok_s
is a proprietary library extension and thus not portable. – External