[C++] 控制台中输出彩色文字 →→→→→进入此内容的聊天室

来自 , 2020-04-11, 写在 C++, 查看 157 次.
URL http://www.code666.cn/view/73e0f748
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <stdio.h>
  4. #include <stdarg.h>
  5.  
  6. using namespace std;
  7.  
  8. void cprintf(char* str, WORD color, ...);
  9.  
  10. int main() {
  11.         cprintf("H", 10);
  12.         cprintf("e", 9);
  13.         cprintf("l", 12);
  14.         cprintf("l", 11);
  15.         cprintf("o", 13);
  16.         cprintf(" ", 10);
  17.         cprintf("W", 15);
  18.         cprintf("o", 2);
  19.         cprintf("r", 5);
  20.         cprintf("l", 8);
  21.         cprintf("d", 14);
  22.         cprintf("!", 4);
  23.         return 0;
  24. }
  25.  
  26. void cprintf(char* str, WORD color, ...) {
  27.         WORD colorOld;
  28.         HANDLE handle = ::GetStdHandle(STD_OUTPUT_HANDLE);
  29.         CONSOLE_SCREEN_BUFFER_INFO csbi;
  30.         GetConsoleScreenBufferInfo(handle, &csbi);
  31.         colorOld = csbi.wAttributes;
  32.         SetConsoleTextAttribute(handle, color);
  33.         cout << str;
  34.         SetConsoleTextAttribute(handle, colorOld);
  35. }

回复 "控制台中输出彩色文字"

这儿你可以回复上面这条便签

captcha