控制台彩色输出

#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;
}

posted on 2014-03-16 21:15  上海—Michael  阅读(215)  评论(0编辑  收藏  举报