I have the following function:
static void cmd_test(char *s)
{
int d = maxdepth;
sscanf(s, "%*s%d", &d);
root_search(d);
}
How can I achieve the same output in a C++ way, rather than using sscanf
?
I have the following function:
static void cmd_test(char *s)
{
int d = maxdepth;
sscanf(s, "%*s%d", &d);
root_search(d);
}
How can I achieve the same output in a C++ way, rather than using sscanf
?
int d = maxdepth;
sscanf(s, "%*s%d", &d);
Reads a string (which does not store anywhere) and then reads a decimal integer. Using streams it would be:
std::string dont_care;
int d = maxdepth;
std::istringstream stream( s );
stream >> dont_care >> d;