2014-10-27 87 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