Hi, I am a C++ begginer.I got some questions here.
I write something like this in VC 2010:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;
int main ()
{
string date;
cout<<"Input the Date(YY-MM-DD):";
cin>>date;
int year,month,day;
sscanf (date.c_str(),"%d-%d-%d",&year,&month,&day);
if(year>1900&&year<2012&&month>0&&month<13&&day>0&&day<32)
cout<<year<<'.'<<month<<'.'<<day<<endl;
else cout<<"error"<<endl;
return 0;
}
|
when i build it, the VC gives a warning:
warning C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. |
so i follow the instruction to use sscanf_s().
but when i build this program in the eclipse cdt with MinGW c++,
it cannot find the function sscanf_s().
then i google this problem and find that the sscanf_s() is something MS added to C++(right?)
and i find that the difference between these two function may be something to do with the buffer size when using %s or %c as format type.
my question is:
1.Is it neccessary to change sscanf() to sscanf_s() when i just using %d as format type, just like my code here?
2.When i use eclipse, it means i can only use sscanf(),right? Is it really unsafe or not good to use this function?
Thanks.
PS:sorry for my poor english.