2012-06-28 3 views
5

이 루프는 매트릭스 영화 (LOL)처럼 화면에서 1과 0을 생성하지만 코드가 실제로 빠르게 실행되는 방식으로 숫자가 천천히 나타납니다.for 루프의 속도를 늦추십시오.

+2

나머지 외부 루프가 실행되지 않는다는 것을 알고 계십니까? –

+0

그래,하지만 난 iterators 그 전에 그것을 제거, 외부 루프를 제외하는 것을 잊었 – Kamran

답변

7

사용 Sleep(3000); 예를

#include <iostream> 
#include <stdlib.h> 
#include <Windows.h> 

using namespace std; 

int main(int argc,char**argv){ 
    cout<<"a"<<endl; 
    Sleep(3000); 
    cout<<"b"<<endl; 

    return 0; 
} 
3

체크 아웃 usleep 당신도 잠을 잘 수 있지만 너무 느릴 것이라고 생각합니다. 당신은 당신이 당신이 임의의 무의미 CIN에 넣을 수 준비가 될 때까지 중지 할 경우

USLEEP(3)    BSD Library Functions Manual    USLEEP(3) 

NAME 
    usleep -- suspend thread execution for an interval measured in microseconds 

LIBRARY 
    Standard C Library (libc, -lc) 

SYNOPSIS 
    #include <unistd.h> 

    int 
    usleep(useconds_t useconds); 

DESCRIPTION 
    The usleep() function suspends execution of the calling thread until either useconds microseconds have elapsed or a signal is delivered to the thread whose action 
    is to invoke a signal-catching function or to terminate the thread or process. The actual time slept may be longer, due to system latencies and possible limita- 
    tions in the timer resolution of the hardware. 

    This function is implemented, using nanosleep(2), by pausing for useconds microseconds or until a signal occurs. Consequently, in this implementation, sleeping 
    has no effect on the state of process timers and there is no special handling for SIGALRM. 

RETURN VALUES 
    The usleep() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. 

ERRORS 
    The usleep() function will fail if: 

    [EINTR]   A signal was delivered to the process and its action was to invoke a signal-catching function. 

SEE ALSO 
    nanosleep(2), sleep(3) 

HISTORY 
    The usleep() function appeared in 4.3BSD. 

BSD       February 13, 1998       BSD 
+0

또는 Windows에서'절전 '. –

1

3000 밀리 초 을 기다리는. 리턴을 누를 때까지 입력을 기다릴 것입니다.