C++ 控制台代码输出控制

在C++控制台应用程序中可以控制控制台输出的字体颜色和 接受任意按键退出

#ifndef CONSOLE_UTILS_H

#define CONSOLE_UTILS_H

#include <windows.h>

#include <conio.h>

#include <iostream>

//default text colors can be found in wincon.h

inline void SetTextColor(WORD colors) {  

    HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hConsole, colors);

}

inline void PressAnyKeyToContinue() {  

   //change text color to white  

  SetTextColor(FOREGROUND_BLUE| FOREGROUND_RED | FOREGROUND_GREEN);

   std::cout << " Press any key to continue" << std::endl;

   while (!_kbhit()){}

   return;

}

#endif

原文地址:https://www.cnblogs.com/ruiying/p/3703320.html