程序员的七夕情人节。。。。

##大神路过,不喜勿喷,请多指教

关键在于使用SetConsoleTextAttribute(out,k)函数设置颜色

#include<iostream>
#include<windows.h>
#include<stdlib.h>
using namespace std;
const int longtime=400;
const int shorttime=40;
HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
void printwrite()
{
    int k;
    for(k=1;k<8;k++)
    {
        SetConsoleTextAttribute(out,k+1);//设置颜色
        cout<<"亲爱的"<<endl<<
            "鹊桥弯弯情谊浓,牛郎织女见面欢。"<<endl<<
            "星河璀璨空中闪,天上人间共缠绵。"<<endl<<
            "手牵手儿心相连,知心的话说不完。"<<endl<<
            "幸福生活绕身边,爱情滚滚似江河,滔滔不绝心中现。"<<endl<<
            "只愿此生永相伴,生生死死手相牵。愿你七夕快乐无限!"<<endl;
        system("cls");//清屏
        Sleep(longtime);
    }
}
void printlove()
{
    int k=0,i,j;
    char piercing_arrow[][34]={//一行33个字符 
"      ☆☆ ☆☆  ☆☆ ☆☆       ",
"     ★★      ★       ★★     ",
"    ☆☆   快乐每一天    ☆☆    ",
"     ★★               ★★     ",
">>>---------I LOVE YOU --------->",
"        ★★         ★★        ",
"          ☆☆     ☆☆          ",
"            ★★  ★★           ",
"               ☆☆              "
};
SetConsoleTextAttribute(out,10);//设置颜色
    for(i=0;i<9;i++)
        for(j=0;j<34;j++)
        {cout<<piercing_arrow[i][j];
        if(j==33)
        cout<<endl;
        Sleep(shorttime);
        }
        system("cls");//清屏
        while(k<7){
   SetConsoleTextAttribute(out,k+7);//设置颜色
    for(i=0;i<9;i++)
      for(j=0;j<34;j++)
      {cout<<piercing_arrow[i][j];
      if(j==33)
      cout<<endl;}
      k++;
        system("cls");
        Sleep(longtime);
        }

}
int main()
{
printwrite();
printlove();
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42433442/article/details/81773410