powerunlimited

[1011]工程程式設計 CW3

Dec 27th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>  
  4. using namespace std ;
  5. int main() {
  6.     // 跑馬燈上的文字
  7.     string  str = "滾滾長江東逝水,浪花淘盡英雄。"
  8.                   "是非成敗轉頭空:青山依舊在,幾度夕陽紅。" ;
  9.    
  10.     int  i ;
  11.     // 列印的起始位置
  12.     int  p = 0 ;
  13.    
  14.     while ( 1 ) {
  15.    
  16.         // 由p 位置起循環列印整行
  17.         for ( i = 0  ; i < str.size() ; i+=2 ) {
  18.             cout << str[(p+i)%str.size()] << str[(p+i+1)%str.size()] <<flush ;
  19.         }
  20.         // 程式休息一秒
  21.   _sleep(1000) ;
  22.         // 將鍵盤游標重到行首
  23.         cout << "\r" ;
  24.    
  25.         p-=2 ;
  26.        
  27.     }
  28.     return 0 ;
  29.    
  30. }
Advertisement
Add Comment
Please, Sign In to add comment