涡轮 如何使用 C++ 终止具有 3 个点的 "Loading..." 程序?
turbo How to terminate a "Loading..." program with having 3 dots using C++?
你可能在很多地方看到过"Loading…"其中3个点(或更多),即"…",首先一个一个地出现,然后在显示所有点后,它们消失,然后再一个一个地出现(这样,总共2次)并退出。
精致的: -
第1阶段:加载。
第二阶段:
加载. .
第三阶段:
加载…
然后,它重复第二次,之后它终止!
因此,为此我准备了一个c++程序,其源代码为:
#include <iostream.h>
#include <time.h>
#include<dos.h>
int main()
{
cout << "Loading";
cout.flush();
for (;;) {
for (int i = 0; i < 3; i++) {
cout << ".";
cout.flush();
sleep(1);
}
cout << "bbb bbb";
}
return 0;
}
程序未终止。它不会停止!我如何编辑它使其终止?
请张贴代码支持的Turbo c++编译器,因为我不是太了解ANSI c++ !!: P
注意:这不是一个重复的问题,所以不要把它标记为重复!!
谢谢,提前!:)
重复第二次,之后终止
你不需要在程序的某个地方有一个2
来做到这一点吗?
也许在for (;;)
的某个地方?与程序中的其他for
类似…
几个反问句:
- 你认为
for (;;)
会做什么? - 为什么你认为把自己限制在Turbo c++编译器是一个好主意?
你写的是for(;;)
。为什么会终止呢?这是一个无尽的循环。
如果您希望外部循环只运行2次,为什么不使用for(int j = 0; j < 2; ++j){other loop}
#include <iostream.h>
#include <time.h>
#include<dos.h>
int main()
{
cout << "Loading";
cout.flush();
//The outer "for" didn't stop in your case, use this:
for (int iterations = 0; iterations < 2; ++iterations) {
for (int i = 0; i < 3; i++) {
cout << ".";
cout.flush();
sleep(1);
}
cout << "bbb bbb";
}
return 0;
}
您至少有两个选择:
-
将
for(;;)
替换为for(int j=0; j < 2; ++j) { /*inner loop here*/ }
-
保持
for(;;)
不变,但执行以下操作:int loopcount = 0; for(;;) /* your loop */ { /* add this after inner loop */ ++loopcount; if(loopcount > 1) break; }
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- C++,系统无法执行指定的程序
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 重载操作程序时出错>>用于类中的字符串 memebr
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 试图在visual studio上用C++创建一个桌面应用程序
- 模板元程序查找相似的连续类型名称
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 如何通过cpp程序运行shell脚本
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- IPC使用多个管道和分支进程来运行Python程序
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 基于boost的程序的静态链接——zlib问题
- 程序崩溃并显示"std::out_of_range"错误
- 在C应用程序中运行C++(带有STL)函数
- 涡轮 如何使用 C++ 终止具有 3 个点的 "Loading..." 程序?
- 你好!我想让我的程序定期显示文本片段。作为"loading bar"的东西.