สอนใช้ printf ()

 

main_animation@2x

 

วันนี้ผมจะมานำเสนอการ printf ให้เป็นรูปมิกกี้เมาส์และรูปหัวใจและการเพื่มสีไปในรูปให้สวยงาม ตอนแรกเราจะประกาศตัวแปลโดยใช้คำสั่ง

#define textcolor(txt,back) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), back*16+txt)

#define resetcolor() SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15)

using namespace std;

เพื่อเป็นการจะเริ่มใช้สีต่างต่างอย่างของผมใช้เป็นสีแดง จะใช้โค๊ด textcolor(12,0); ซึ่งสีแดงจะใช้เป็นเลข (12,0) และเราจะปิดท้ายด้วยคำสั่ง

resetcolor(); เป็นการเสร็จสิ้น

นี้คือตัวอย่างโค๊ตที่ทำนะครับ

#include “stdafx.h”

#include <iostream>
#include <windows.h>
#define textcolor(txt,back) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), back*16+txt)

#define resetcolor() SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15)

using namespace std;

int main()
{

printf(“\n\n\n”);

textcolor(12,0);
printf(“\n______________$$$$$$$”);
printf(“\n_____________$$$$$$$$$”);
printf(“\n____________$$$$$$$$$$$”);
printf(“\n____________$$$$$$$$$$$”);
printf(“\n____________$$$$$$$$$$$________________$$$$$$$$_______$$$$$$$$”);
printf(“\n_____________$$$$$$$$$_______________$$$$$$$$$$$_____$$$$$$$$$$$”);
printf(“\n_____$$$$$$_____$$$$$$$$$$__________$$$$$$$$$$$$$___$$$$$$$$$$$$$”);
printf(“\n____$$$$$$$$__$$$$$$_____$$$_______$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$”);
printf(“\n___$$$$$$$$$$$$$$$$_________$______$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$”);
printf(“\n___$$$$$$$$$$$$$$$$______$__$_______$$$$$$$$$$$$$$$$$$$$$$$$$$$$$”);
printf(“\n___$$$$$$$$$$$$$$$$_____$$$_$________$$$$$$$$$$$$$$$$$$$$$$$$$$$”);
printf(“\n___$$$$$$$$$$$__________$$$_$_____$$__$$$$$$$$$$$$$$$$$$$$$$$$$”);
printf(“\n____$$$$$$$$$____________$$_$$$$_$$$$___$$$$$$$$$$$$$$$$$$$$$”);
printf(“\n______$$$__$$__$$$______________$$$$______$$$$$$$$$$$$$$$$$$”);
printf(“\n___________$$____$_______________$__________$$$$$$$$$$$$$$”);
printf(“\n___________$$____$$$____________$$____________$$$$$$$$$$”);
printf(“\n_______________$$$_$$$$$$_$$$$$__________________$$$”);
printf(“\n________________$$____$$_$$$$$”);
printf(“\n_______________$$$$$___$$$$$$$$$$”);
printf(“\n_______________$$$$$$$$$$$$$$$$$$$$”);
printf(“\n_______________$$_$$$$$$$$$$$$$$__$$”);
printf(“\n_______________$$__$$$$$$$$$$$___$_$”);
printf(“\n______________$$$__$___$$$______$$$$”);
printf(“\n______________$$$_$__________$$_$$$$”);
printf(“\n______________$$$$$_________$$$$_$_$”);
printf(“\n_______________$$$$__________$$$__$$”);
printf(“\n_____$$$$_________$________________$”);
printf(“\n___$$$___$$______$$$_____________$$”);
printf(“\n__$___$$__$$_____$__$$$_____$$__$$”);
printf(“\n_$$____$___$_______$$$$$$$$$$$$$”);
printf(“\n_$$_____$___$_____$$$$$_$$___$$$”);
printf(“\n_$$_____$___$___$$$$____$____$$”);
printf(“\n__$_____$$__$$$$$$$____$$_$$$$$”);
printf(“\n__$$_____$___$_$$_____$__$__$$$$$$$$$$$$”);
printf(“\n___$_____$$__$_$_____$_$$$__$$__$______$$$”);
printf(“\n____$$_________$___$$_$___$$__$$_________$”);
printf(“\n_____$$_$$$$___$__$$__$__________________$”);
printf(“\n______$$____$__$$$____$__________________$”);
printf(“\n_______$____$__$_______$$______________$$”);
printf(“\n_______$$$$_$$$_________$$$$$$$__$$$$$$”);
printf(“\n__________$$$_________________$$$$$”);
resetcolor();

printf(“\n\n\n\n\n\n\n”);

textcolor(11,0);
printf(“My Name is Mr.Todsapon Buakhampho\n”);
printf(“My nickname is ToD\n”);
printf(“My birthday is the 25th of March 1996\n”);
printf(“My hobby is Game\n”);
printf(“My favorite sport is Football\n”);
printf(“My favorite color is blue\n”);
resetcolor();
system(“pause”);
return 0;
}

นี้ผลลัพธ์ที่แสดงของโค๊ด c++

1

ขอบคุณครับ

ผิดพลาดประการใดก็ขอโทษด้วยครับ

Todspon Buakhampho
at GlurGeek.Com

Leave a Reply

© 2022 GlurGeek.Com