首页 > 技术文章 > 控制台彩色输出

duyy 2014-03-16 21:15 原文

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;
void SetColor(unsigned short ForeColor=3,unsigned short BackGroundColor=0)
{
  HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  SetConsoleTextAttribute(hCon,ForeColor|BackGroundColor);
}


int _tmain(int argc, LPTSTR argv[])
{
  SetColor();
  std::cout<<"Hello world!"<<endl;
  SetColor(40,30);
  std::cout<<"Hello world!"<<endl;
  std::cout<<"Hello world!"<<endl;
  system("pause");
  return 0;
}

推荐阅读