2014-10-27 34 views
-1

注意我是初学者。睡眠(4000)显示。每1000(C++)

我想要做的是显示一个“。”定时器每1000秒钟。我想要“。”在cout后面显示。

#include <iostream> 
#include <windows.h> 


using namespace std; 

int main() 

{ 

    char uname; 
    char pword; 

    cout << "Initializing EKG"; 
    Sleep(4000); 
     /* while/for Sleep(1000) cout << "." 
     while Sleep(1000*2) cout << "." 
     */ 
    //Something along those lines I am trying to achieve. 
    //Can't I use a ++ or something similar to increase the . to .. to ... to ....? 

    return 0; 

} 
+2

有时我想知道人们是否在撰写问题时看预览。 – rightfold 2014-10-27 22:38:55

+0

'睡眠'以毫秒为单位,而不是几秒,它的价值。 – 2014-10-27 22:55:46

+0

哪个平台和操作系统?你可能想要一个单独的线程执行一个打印'。'的函数。每一秒。这将允许您的程序打印'。'同时执行其他操作。 – 2014-10-27 22:57:08

回答

4

你可以使用一个简单的for循环来做到这一点。

for(int i = 0; i < 4; i++){ 
     Sleep(1000); 
     cout << "."; 
} 
+0

谢谢,效果很好。当使用while循环时,它将是一个不间断的“......” – EvanEKG 2014-10-27 23:39:01

+0

您也可以使用如下所示的while循环: int i = 0; (i <4)睡眠(1000); cout <<“。”; i ++; } – Mosa 2014-10-28 00:33:01

+0

莫莎你很棒,非常感谢你。非常感谢。 – EvanEKG 2014-10-29 08:19:04