
让c++程序暂停的方法有哪些?
例如说我用一个for循环循环三次,第二次的时候我想让程序暂停,按任意键继续,有哪些方法可以实现,getch我试过,似乎不行,望高手指点我用getch是编译总是出错,出错信...
例如说我用一个for循环循环三次,第二次的时候我想让程序暂停,按任意键继续,有哪些方法可以实现,getch我试过,似乎不行,望高手指点
我用getch是编译总是出错,出错信息如下: implicit declaration of function `int getchar(...)',程序循环时,我是为了显示一些信息,所以暂停 展开
我用getch是编译总是出错,出错信息如下: implicit declaration of function `int getchar(...)',程序循环时,我是为了显示一些信息,所以暂停 展开
展开全部
程序暂停:
在C++里使用
#include <conio.h>
getch();
或者
#include <cstdio>
getchar();
在windows中,还可以使用
#include <cstdlib>
system("pause");
如果单纯想要查看结果,还可以使用sleep
windows中
#include <windows>
Sleep(int);
在linux中
#include <unistd.h>
sleep(int);
在C++里使用
#include <conio.h>
getch();
或者
#include <cstdio>
getchar();
在windows中,还可以使用
#include <cstdlib>
system("pause");
如果单纯想要查看结果,还可以使用sleep
windows中
#include <windows>
Sleep(int);
在linux中
#include <unistd.h>
sleep(int);
展开全部
1.程序末尾即return 0;前,加 while(1);
2.程序末尾即return 0;前,加 scanf("\n");(需加头文件<cstdio>)
3.程序末尾即return 0;前或者需暂停处,加 system(“pause”);(需加头文件<iostream>)(推荐,即你想要的“按任意键继续”)
2.程序末尾即return 0;前,加 scanf("\n");(需加头文件<cstdio>)
3.程序末尾即return 0;前或者需暂停处,加 system(“pause”);(需加头文件<iostream>)(推荐,即你想要的“按任意键继续”)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
判断就行了嘛
for (int i = 0; i < 3, i++)
{
if (i = 2)
{
getch();
}
}
for (int i = 0; i < 3, i++)
{
if (i = 2)
{
getch();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
system("pause");
有时得加头文件#include<windows.h>
有时得加头文件#include<windows.h>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用getch需要包含头文件#include<conio.h>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询