C ++中的sscanf功能? [英] sscanf feature in C++?

查看:90
本文介绍了C ++中的sscanf功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在C ++中有sscanf功能吗?我想因为C ++是C的超集。

所以以下是有效的C ++代码。这是真的吗?


char * buf =" 10:25:33";

sscanf(buf,"%d:%d:% d",& h,& m,& s);


请指教。谢谢!!

Do we have sscanf feature in C++? I guess since C++ is superset of C.
So the following are valid C++ code. Is that true?

char* buf = "10:25:33";
sscanf(buf, "%d:%d:%d", &h, &m, &s);

Please advise. thanks!!

推荐答案

文章< ba ********************* *****@posting.google.com>,

Matt< jr ******** @ hotmail.com>写道:
In article <ba**************************@posting.google.com >,
Matt <jr********@hotmail.com> wrote:
我们在C ++中有sscanf功能吗?我想因为C ++是C的超集。
所以以下是有效的C ++代码。这是真的吗?

char * buf =" 10:25:33" ;;
sscanf(buf,"%d:%d:%d",& h,& ; m,& s);

请指教。谢谢!!


由于这是comp.lang.c,我们可以给你的最好答案是这是

完全有效的C。


如果你在comp.lang.c ++中问这个问题,他们会告诉你它也是完全有效的C ++(假设你有一个合适的使用方法)

范围内的指令或使用C风格的标题名称而不是C ++风格的标题

名称),并且可能还提到std :: strstream作为更多的C ++ - ish

另类。

dave


-

Dave Vandervies dj ****** @ csclub.uwaterloo.ca 错了。
Do we have sscanf feature in C++? I guess since C++ is superset of C.
So the following are valid C++ code. Is that true?

char* buf = "10:25:33";
sscanf(buf, "%d:%d:%d", &h, &m, &s);

Please advise. thanks!!
Since this is comp.lang.c, the best answer we can give you is "This is
perfectly valid C".

If you go ask this in comp.lang.c++, they''ll tell you that it''s also
perfectly valid C++ (assuming you have an appropriate using directive in
scope or use the C-style header names instead of the C++-style header
names), and possibly also mention std::strstream as a more C++-ish
alternative.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.caWrong.



我可以成为原因是在C新闻组中显示不完整/不正确的C ++知识知识

? --Michael Rubenstein和Ian Woods在comp.lang.c


May I be excused for showing incomplete/incorrect knowledge of C++ knowledge
in a C newsgroup? --Michael Rubenstein and Ian Woods in comp.lang.c


Matt写道:
Matt wrote:
我们在C ++中是否有sscanf功能?


" We",在comp.lang.c中,不,因为我们在C中编程。

comp.lang中的人。 c ++会告诉你他们有sscanf,但很多人可能会告诉你使用一些C ++功能。相反。

我猜是因为C ++是C的超集。


你的前提是错误的。 C ++不是C的超集。无论谁告诉你

应该被忽略:他是个傻瓜。

所以以下是有效的C ++代码。


我们不知道:comp.lang.c不做C ++。但是......这是真的吗?

char * buf =" 10:25:33" ;;
sscanf(buf,"%d:%d:%d",& h,& m,& s);
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);




这个合法的C程序


#include< stdio.h> ;


int main(无效)

{

char * buf =" 10:25:33";

int h,m,s;

sscanf(buf,"%d:%d:%d",& h,& m,& s);

printf(%d小时+%d分钟+%d秒\ n,h,m,s);

返回0;

}


产生此输出

10小时+25分钟+33秒


这个可能合法(但检查comp.lang.c ++他们做C ++)C ++

程序


#include< cstdio>

int main()

{

char * buf =" 10:25:33";

int h, m,s;

sscanf(buf,"%d:%d:%d",& h,& m,& s);

printf (%d小时+%d分钟+%d seco nds \ n",h,m,s);

}


产生此输出

10小时+25分钟+ 33秒



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


Matt写道:
Matt wrote:
我们在C ++中有sscanf功能吗?


这是comp.lang.c.你想要comp.lang.c ++。

我猜是因为C ++是C的超集。


这是一个错误的陈述。

所以以下是有效的C ++代码。这是真的吗?

char * buf =" 10:25:33" ;;
sscanf(buf,"%d:%d:%d",& h,& ; m,& s);
Do we have sscanf feature in C++?
This is comp.lang.c. You want comp.lang.c++.
I guess since C++ is superset of C.
This is a false statement.
So the following are valid C++ code. Is that true?

char* buf = "10:25:33";
sscanf(buf, "%d:%d:%d", &h, &m, &s);




< OT>

C标准库大部分都包含在C ++中。

< / OT>

Brian



<OT>
The C standard library, for the most part, is included in C++.
</OT>
Brian


这篇关于C ++中的sscanf功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆