sscanf()的C ++替代品 [英] C++ alternative to sscanf()
本文介绍了sscanf()的C ++替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有以下功能:
static void cmd_test(char *s)
{
int d = maxdepth;
sscanf(s, "%*s%d", &d);
root_search(d);
}
如何用C ++方式而不是使用< sscanf
?
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;
这篇关于sscanf()的C ++替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文