两个i / o问题 [英] Two i/o questions
问题描述
我如何在C ++(!)中执行此操作(使用C99 stdlib.h):
fflush(stdin);
我如何制作类似按任意键继续...的内容。在
标准方式?我的意思是如果我使用getchar()(再次来自C99),如果需要
按< Enterkey。如何在不按< Enter>的情况下执行此操作?任何
无缓冲标准C ++变体?也许一些std :: cin成员函数?
How do I do in C++ (!) this operation (usin C99 stdlib.h):
fflush(stdin);
And how do I make something like "Press any key to continue..." in
standard way? I mean if I use getchar() (again from C99), if requires
pressing <Enterkey. How do I do it without pressing <Enter>? Any
unbuffered standard C++ variant? Maybe some std::cin member function?
推荐答案
文章< 685c8634-bcfd-4f7e-b869-0d0e5c01dc20
@ m73g2000hsh.googlegroups.com>, is********@gmail.com 说。 ..
In article <685c8634-bcfd-4f7e-b869-0d0e5c01dc20
@m73g2000hsh.googlegroups.com>, is********@gmail.com says...
如何在C ++(!)中执行此操作(使用C99 stdlib.h):
fflush (标准输入);
How do I do in C++ (!) this operation (usin C99 stdlib.h):
fflush(stdin);
这在C中给出了未定义的行为。有许多方法可以在C ++中获得未定义的
行为,尽管我不知道为什么你想要这样做。
This gives undefined behavior in C. There are many ways to get undefined
behavior in C++, though I''m not sure why you''d want to do so.
我如何制作类似按任意键继续...的内容。在
标准方式?我的意思是如果我使用getchar()(再次来自C99),如果需要
按< Enterkey。如何在不按< Enter>的情况下执行此操作?任何
无缓冲标准C ++变体?也许一些std :: cin成员函数?
And how do I make something like "Press any key to continue..." in
standard way? I mean if I use getchar() (again from C99), if requires
pressing <Enterkey. How do I do it without pressing <Enter>? Any
unbuffered standard C++ variant? Maybe some std::cin member function?
编号C ++允许您以不同方式_view_ I / O,但它对底层系统的基本要求是b / b
与C的人基本相同
-
后来,
Jerry。
宇宙是自己想象的虚构。
No. C++ allows you to _view_ the I/O in different ways, but the basic
requirements it makes of the underlying system are essentially identical
to those of C.
--
Later,
Jerry.
The universe is a figment of its own imagination.
Isliguezze写道:
Isliguezze wrote:
如何在C ++(!)中执行此操作(使用C99 stdlib.h):
fflush(stdin);
How do I do in C++ (!) this operation (usin C99 stdlib.h):
fflush(stdin);
什么是冲洗stdin给你的?刷新将导致缓冲数据被推出。
被推出。
What does flusing stdin give you? flushing will cause buffered data to
be pushed out.
>
我如何制作类似按任意键继续......的内容。在
标准方式?我的意思是如果我使用getchar()(再次来自C99),如果需要
按< Enterkey。如何在不按< Enter>的情况下执行此操作?任何
无缓冲标准C ++变体?也许一些std :: cin成员函数?
>
And how do I make something like "Press any key to continue..." in
standard way? I mean if I use getchar() (again from C99), if requires
pressing <Enterkey. How do I do it without pressing <Enter>? Any
unbuffered standard C++ variant? Maybe some std::cin member function?
这是特定于实现的。我记得在Borland C ++ 3.1中,有一个getch()函数可以做你想要的。最好只说按
输入继续......如果你想要便携性,请留下它。
-
Daniel Pitts的'科技博客:< http://virtualinfinity.net/wordpress/>
It is implementation specific. I remember in Borland C++ 3.1, there was
a getch() function that did what you want. Its better to just say "Press
enter to continue..." and leave it at that if you want portability.
--
Daniel Pitts'' Tech Blog: <http://virtualinfinity.net/wordpress/>
" Isliguezze"写道:
"Isliguezze" wrote:
如何在C ++(!)中执行此操作(使用C99 stdlib.h):
fflush (标准输入);
How do I do in C++ (!) this operation (usin C99 stdlib.h):
fflush(stdin);
要清除系统维护的输入缓冲区,请参阅istream :: ignore()。
您可能必须在它之前使用ios :: clear()因为流处于一个失败的状态,并且它不会监听任何命令而是清除。如果流处于失败状态,有很多方法可以看到
。
To clear the input buffer maintained by the system, see istream::ignore().
You may have to precede it with ios::clear() because the stream is in a fail
state and it will not listen to any command but clear. There are ways to see
if the stream is in a fail state.
如何制作类似按任意键的内容继续......在
标准方式?我的意思是如果我使用getchar()(再次来自C99),如果需要
按< Enterkey。如何在不按< Enter>的情况下执行此操作?任何
无缓冲标准C ++变体?也许一些std :: cin成员函数?
And how do I make something like "Press any key to continue..." in
standard way? I mean if I use getchar() (again from C99), if requires
pressing <Enterkey. How do I do it without pressing <Enter>? Any
unbuffered standard C++ variant? Maybe some std::cin member function?
我知道做的唯一方法是按任意键是非标准的。只有
微软会认为向上箭头键和它的表兄弟不是一个键,
所以这个消息从一开始就是错误的。最简单的方法是使用按
输入并摆脱任何不受欢迎的输入。
The only ways I know of doing "Press any key" are non-standard. Only
Microsoft would think that the up arrow key and it''s cousins was not a key,
so the message was wrong from the get-go. Easiest way out is to use "Press
enter" and get rid of any undesired input.
这篇关于两个i / o问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!