Matt said:
Do we have sscanf feature in C++?
"We", in comp.lang.c, don't, because we program in C. The folks in
comp.lang.c++ would tell you that they have sscanf, but many are likely
to tell you to use some C++ "feature" instead.
I guess since C++ is superset of C.
Your premise is wrong. C++ is not a superset of C. Whoever told you
that should be ignored: he is a fool.
So the following are valid C++ code.
We don't know: comp.lang.c doesn't do C++. But..
Is that true?
char* buf = "10:25:33";
sscanf(buf, "%d:%d:%d", &h, &m, &s);
This legal C program
#include <stdio.h>
int main(void)
{
char *buf = "10:25:33";
int h, m, s;
sscanf(buf, "%d:%d:%d", &h, &m, &s);
printf("%d hours + %d minutes + %d seconds\n", h, m, s);
return 0;
}
produces this output
10 hours + 25 minutes + 33 seconds
and this probably legal (but check comp.lang.c++ where they do C++) C++
program
#include <cstdio>
int main()
{
char *buf = "10:25:33";
int h, m, s;
sscanf(buf, "%d:%d:%d", &h, &m, &s);
printf("%d hours + %d minutes + %d seconds\n", h, m, s);
}
produces this output
10 hours + 25 minutes + 33 seconds