在C ++中是否有像Pause或Nope这样的命令?
我只想让程序暂停一段时间。
谢谢。
I just want the programme to stop for a while.
Thanks.
" ;济"写道:
"Jackie" writes:
我只想让程序暂停一段时间。
I just want the programme to stop for a while.
你最好的选择可能是系统()功能自
它可以让你与操作系统进行交互。例如,在Windows中,尝试
system(暂停);
Your best bet is probably the system() function since
it lets you interact with the OS. For example, in Windows, try
system("pause");
Jackie写道:
Jackie wrote:
我只是希望程序停止一段时间。
谢谢。
I just want the programme to stop for a while.
Thanks.
你想要程序停止直到你输入?如果是这样,请使用cin:
string str;
cin>> str;
这将停止程序直到你按下回车键。
Alvin
Do you want the program to stop until you hit enter? If so, use cin like:
string str;
cin >> str;
That will stop the program till you press the Enter key.
Alvin
>
On Sun,2006年1月29日08:43:57 -0800,osmium < r1 ******** @ comcast.net>
写道:
On Sun, 29 Jan 2006 08:43:57 -0800, "osmium" <r1********@comcast.net>
wrote:
" Jackie"写道:
"Jackie" writes:
我只是希望程序暂停一段时间。
I just want the programme to stop for a while.
你最好的选择可能是system()函数,因为
系统(暂停);
Your best bet is probably the system() function since
it lets you interact with the OS. For example, in Windows, try
system("pause");
在C类型逻辑中...我创建一个虚拟字符串并使用获取()暂停一个
程序。
#include< stdio.h>
char junk [ 81];
printf(" routine_name(%d):"
"点击返回以继续暂停的程序... \ n,_ _ _ _ _ _ _ _ _ ;
得到(垃圾);
-----------------
得到(垃圾);
提示在程序中输入键盘输入也有助于清除错误的击键。
如果发生错误的击键且暂停非常重要......你应该
测试一个空字符串。以下回应错误的击键:
if(junk [0])
{
printf(" routine_name(%) d):junk =%s \ n",_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b__ LINE __宏告诉你确切的行,并在printf语句中包含例程的
名称,你可以找到这个暂停
轻松点。
设置断点也可以。但我通常不会使用
断点进行调试。我喜欢打印报表。我经常将它们写入日志文件
并使用#define打开和关闭暂停功能。
#define暂停1
如果(暂停)得到(垃圾);
我抱歉没有足够的C ++技能来制作代码
干净而华丽。幸运的是,C ++完全支持C语言。我的赌注是
这里的C ++大师将教会我们两个更好的方法。 :))
In C type logic ... I create a dummy string and use gets() to pause a
program.
#include <stdio.h>
char junk[81];
printf("routine_name(%d):"
" hit return to continue the paused program ...\n", __LINE__);
gets(junk);
-----------------
gets(junk); is good for clearing erroneous key strokes before
prompting for keyboard input in programs as well.
If erroneous keystrokes occur and the pause is critical ... you should
test for a null string. The following echos the erroneous keystrokes:
if(junk[0])
{
printf("routine_name(%d): junk = %s\n", __LINE__, junk);
gets(junk);
}
The "__LINE__" macro tells you the exact line and by including the
name of the routine in your printf statement you can find this pause
point easily.
Setting a break point would work too. But I usually don''t debug using
break points. I like print statements. I often write them to log files
and turn the pause feature on and off with a #define.
#define pause 1
if(pause) gets(junk);
My apologies for not having sufficient C++ skills to make the code
clean and gorgeous. Fortunately C is fully supported in C++. My bet is
a C++ guru in here will teach us both a better way. :))