<帮助与GT;简单的暂停需要。 [英] <Help> Simple Pause Needed.

查看:46
本文介绍了<帮助与GT;简单的暂停需要。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这必须是一个简单的,但我在教科书中找不到答案




我怎样才能得到一个简单的在输出行之后暂停,只需等待按键继续按下




基本上:按任意键继续.. 。


我相信我正在寻找的东西是...... ....


cin.get


但是不知道它的确切语法。


我知道它很简单....我可以用眼睛来制作和调用函数

关闭了但这让我感到很不舒服......


谢谢。

解决方案

达芬奇 < BL *** @ blank.com>在消息中写道

news:ek ******************************** @ 4ax.com ...

好的,这必须是一个简单的,但我在教科书中找不到答案。

我怎样才能得到一个简单的在输出线之后暂停,只需等待按下任何按键继续前进?

基本上:按任意键继续......


你几乎可以得到这个。对于大多数带键盘的系统,

输入是''行缓冲'',因此在用户按下''Enter'之前,你的程序看不到任何

输入'(又名''返回'')键。

这样可以在将输入提交到

程序之前编辑输入。想想'fumble-fingers''和''退格键'':-)


所以对于这样的系统,你可以有一个''按Enter继续'',

以几种不同的方式。


你可以使用cin.get(),但我只会用它作为前奏

到程序的终止,因为即使''get()''仅
提取单个字符,用户也可以轻松输入

例如十个字符(或更多),这些字符将会在''缓冲区''中等待,并显示在

下一个输入请求中。所以你需要额外的代码来丢弃它们。

(cin.ignore()等)


我发现最有用的通用方法这是

与(非成员)''std :: getline()''函数,它将

提取所有字符直到第一个换行符,并且

将它们存储在std :: string对象中。 (换行符本身

已提取但未存储)。然后把绳子扔掉,

或者把它交给你的猫。 :-)


示例:


#include< iostream>

#include< string>


void wait4user()

{

std :: string response;

std :: cout << 按Enter键继续;

std :: getline(std :: cin,response);

}


int main()

{

std :: cout<< 你好;

wait4user();

std :: cout<< world \ n;

wait4user();

返回0;

}


我相信我正在寻找的东西是...... .... / cn.get


cin.get()会起作用,但是我有上面提到的缺点。

但不知道它的确切语法。


这就是书的用途。 :-)任何好的C ++编译器

也会提供标准库的文档。

我知道它很简单....我可以用眼睛制作和调用函数
关闭了但这让我很不自在......




睁开眼睛。 :-)


HTH,

-Mike


优秀!


它就像一个魅力。


我不知道有关cin.get的信息,并且在

缓冲区中有字符。感谢!我敢打赌,将来可以节省很多心。


噢,加油......骑车时睁大眼睛没有意思! :-)


再次感谢。

星期二,2003年9月30日22:19:06 GMT,Mike Wahler

< mk ****** @ mkwahler.net>写道:

" da Vinci" < BL *** @ blank.com>在消息中写道
新闻:ek ******************************** @ 4ax.com ..。< blockquote class =post_quotes>好的,这必须是一个简单的,但我在教科书中找不到答案。

如何在输出后得到一个简单的暂停线,只是等待任何按键继续前进?

基本上:按任意键继续......


<你几乎可以得到这个。对于大多数带键盘的系统,
输入是行缓冲,因此在用户按下输入(又称返回)之前,您的程序看不到任何输入。键。
这可以在将输入提交到
程序之前编辑输入。想想'fumble-fingers''和''退格键'':-)

所以对于这样的系统,你可以有一个''按Enter继续'',
in几种不同的方式。

您可以使用cin.get(),但我只会将其用作程序终止的前奏,因为即使'' get()''只提取单个字符,用户可以轻松输入
例如十个字符(或更多),这些字符仍然会在缓冲区中等待,并显示在
下一个输入请求中。所以你需要额外的代码来丢弃它们。
(cin.ignore()等)

我发现最有用的通用方法是
(非成员)''std :: getline()''函数,它将提取所有字符直到第一个换行符,并将它们存储在std :: string对象中。 (换行符本身
被提取但未存储)。然后把绳子扔掉,
或把它交给你的猫。 :-)

例如:

#include< iostream>
#include< string>

void wait4user()
{
std :: string response;
std :: cout<< 按Enter键继续;
std :: getline(std :: cin,response);
}
int main()
{
std :: cout<< Hello"
wait4user();
std :: cout<< world \ n;
wait4user();
返回0;
}


我相信我正在寻找的东西是...... .... cn.get



cin.get()可行,但有我上面提到的缺点。


但是不知道它的确切语法。



这就是书的内容对于。 :-)任何好的C ++编译器
也会提供标准库的文档。


我知道它很简单....我可以制作和用眼睛打电话的功能
关闭了但这让我很不自在......



睁开眼睛。 :-)

HTH,
-Mike




da Vinci写道:

优秀!




请不要发帖。阅读FAQ的第5部分,了解发布指南。

http://www.parashift.com/c++-faq-lite/


-Kevin

-

我的电子邮件地址有效,但会定期更改。

要联系我,请使用最近发布的地址。


OK, this has got to be a simple one and yet I cannot find the answer
in my textbook.

How can I get a simple pause after an output line, that simply waits
for any key to be pressed to move on?

Basically: "Press any key to continue..."

I beleive that I am looking for is something along the lines of a....

cin.get

but do not know the exact syntax for it.

I know it is so simple.... I can make and call functions with eyes
closed yet this illudes me...

Thanks.

解决方案

"da Vinci" <bl***@blank.com> wrote in message
news:ek********************************@4ax.com...

OK, this has got to be a simple one and yet I cannot find the answer
in my textbook.

How can I get a simple pause after an output line, that simply waits
for any key to be pressed to move on?

Basically: "Press any key to continue..."
You can get almost that. With most systems with keyboards,
input is ''line buffered'', so your program doesn''t see any
input until the user presses the ''Enter'' (aka ''return'') key.
This lets one edit the input before submitting it to the
program. Think ''fumble-fingers'', and ''backspace key'' :-)

So for such systems, you can have a ''Press Enter to continue'',
in a few different ways.

You could use cin.get(), but I''d only use that as a prelude
to the program''s termination, since even though ''get()'' only
extracts a single character, the user could easily type in
e.g. ten characters (or more), and those characters would
still be waiting in a ''buffer'', and be presented to the
next input request. So you''d need extra code to discard them.
(cin.ignore() etc.)

I find the most useful general purpose way to do this is
with the (nonmember) ''std::getline()'' function, which will
extract all characters up to the first newline character, and
store them in a std::string object. (The newline character itself
is extracted but not stored). Then just throw the string away,
or give it to your cat. :-)

Example:

#include <iostream>
#include <string>

void wait4user()
{
std::string response;
std::cout << "Press Enter to continue";
std::getline(std::cin, response);
}

int main()
{
std::cout << "Hello";
wait4user();
std::cout << "world\n";
wait4user();
return 0;
}


I beleive that I am looking for is something along the lines of a....

cin.get
cin.get() would work, but has the disadvantage I cited above.

but do not know the exact syntax for it.
That''s what books are for. :-) Any good C++ compiler
will also provide documentation for the standard library.

I know it is so simple.... I can make and call functions with eyes
closed yet this illudes me...



Open your eyes. :-)

HTH,
-Mike


Excellent!

It worked like a charm.

I didnt know that info about the cin.get and having characters in the
buffer. Appreciate that! I bet that will save a great deal of heart
ache in the future.

Aw, come on.... keeping your eyes open during the ride is no fun!! :-)

Thanks again.
On Tue, 30 Sep 2003 22:19:06 GMT, "Mike Wahler"
<mk******@mkwahler.net> wrote:

"da Vinci" <bl***@blank.com> wrote in message
news:ek********************************@4ax.com.. .

OK, this has got to be a simple one and yet I cannot find the answer
in my textbook.

How can I get a simple pause after an output line, that simply waits
for any key to be pressed to move on?

Basically: "Press any key to continue..."



You can get almost that. With most systems with keyboards,
input is ''line buffered'', so your program doesn''t see any
input until the user presses the ''Enter'' (aka ''return'') key.
This lets one edit the input before submitting it to the
program. Think ''fumble-fingers'', and ''backspace key'' :-)

So for such systems, you can have a ''Press Enter to continue'',
in a few different ways.

You could use cin.get(), but I''d only use that as a prelude
to the program''s termination, since even though ''get()'' only
extracts a single character, the user could easily type in
e.g. ten characters (or more), and those characters would
still be waiting in a ''buffer'', and be presented to the
next input request. So you''d need extra code to discard them.
(cin.ignore() etc.)

I find the most useful general purpose way to do this is
with the (nonmember) ''std::getline()'' function, which will
extract all characters up to the first newline character, and
store them in a std::string object. (The newline character itself
is extracted but not stored). Then just throw the string away,
or give it to your cat. :-)

Example:

#include <iostream>
#include <string>

void wait4user()
{
std::string response;
std::cout << "Press Enter to continue";
std::getline(std::cin, response);
}

int main()
{
std::cout << "Hello";
wait4user();
std::cout << "world\n";
wait4user();
return 0;
}


I beleive that I am looking for is something along the lines of a....

cin.get



cin.get() would work, but has the disadvantage I cited above.


but do not know the exact syntax for it.



That''s what books are for. :-) Any good C++ compiler
will also provide documentation for the standard library.


I know it is so simple.... I can make and call functions with eyes
closed yet this illudes me...



Open your eyes. :-)

HTH,
-Mike




da Vinci wrote:

Excellent!



Please don''t top-post. Read section 5 of the FAQ for posting guidelines.

http://www.parashift.com/c++-faq-lite/

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


这篇关于&LT;帮助与GT;简单的暂停需要。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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