learn "_stscanf_s"
#define _stscanf_s sscanf_s
sscanf_s
msdn: Read formatted data from a string.
int sscanf_s(
const char *buffer, //stored data
const char *format [,
argument ] ...
);
Return value is the number of fields successfully.
eg:
char temp = "15 12 14...";
char var[4];
char c;
int i;
float f;
sscanf_s(temp, "%s", var, _countof(var)); //15
sscanf_s(temp, "%c", c, sizeof(char)); //1
sscanf_s(temp, "%d", &i); //15
sscanf_s(temp, "%f", &f); //15.000000
string time("2016-01-07_14:58:23");
tm stm = {0};
sscanf_s(time.c_str(), "%4d-%2d-%2d_%2d:%2d:%2d",
&stm.tm_year, &stm.tm_mon, &stm.tm_mday,
&stm.tm_hour, &stm.tm_min, &stm.tm_sec);
浙公网安备 33010602011771号