Linux C 文字及背景輸出顏色效果測試~

 

嘿嘿,發覺好好玩~ios

發現了 ESC[*m 的命令後,嘗試各類效果~ide

使用方法上次的文章講過啦,這裏不重複,直接上代碼:測試

 

  
  
  
  
  1. #include <stdio.h>  
  2. #include <sstream>  
  3. #include <iostream>  
  4. #include <string>  
  5. using namespace std;  
  6.   
  7. int main()  
  8. {  
  9.     // ESC效果測試  
  10.     for(int i = 0; i <= 100; ++i){       // i是效果的代號  
  11.          // 將整型i轉換爲string型  
  12.          string c;  
  13.          ostringstream oss;  
  14.          oss << i;  
  15.          c = oss.str();  
  16.          string styleStr = "\033[" + c + "m";  
  17.          // 上面即轉換成這樣的格式: printf ("\033[0m");  
  18.          if(0 != i &&  i % 5){   // 5個換行,輸出格式控制  
  19.              printf("\n"); 
  20.          }  
  21.           
  22.          printf("\033[%sm%dm的效果!\033[0m\t", c.c_str(), i);  
  23.     }  
  24.   
  25.     getchar();  
  26.     return 0;  
  27. }  

 

 

效果:spa

Linux C 顏色及背景控制效果圖

相關文章
相關標籤/搜索