跳到正文

个人记录

C++基础代码

用户 767762约 6 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 6 分钟

版本

  1. v1当前

基础代码4.0

C++
#include<ctime>
#include<cmath>
#include<conio.h>
#include<fstream>
#include<iomanip>
#include<direct.h>
#include<iostream>
#include<algorithm>
#include<windows.h>
#define black 0
#define deepblue 1
#define green 2
#define lightblue 3
#define red 4
#define purple 5
#define yellow 6
#define lightgrey 7
#define grey 8
#define blue 9
#define lightgreen 10
#define cyan 11
#define lightred 12
#define lightpurple 13
#define lightyellow 14
#define white 15
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
const int waittime=75;
void SetPos(float x,float y){COORD pos;pos.X=x;pos.Y=y;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
void SetPos(int x,int y){COORD pos;pos.X=x;pos.Y=y;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
void color(int fgc,int bgc){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),16*bgc+fgc);}
void slow(const char* p,int w){for(;;){if(*p!=0)cout<<*p++;else break;Sleep(w);}}
void slow(const char* p){for(;;){if(*p!=0)cout<<*p++;else break;Sleep(waittime);}}
void appear(bool a){CONSOLE_CURSOR_INFO c;c.bVisible=a;SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&c);}
float Sin(int a){return sin(3.141593*a/180);}
float Cos(int a){return cos(3.141593*a/180);}
float SinP(int a){return sin(3.141593*a);}
float CosP(int a){return cos(3.1416*a);}
POINT mousepos(){/*检测鼠标位置:pt.x,pt.y  POINT pt=mousepos();cout<<"鼠标坐标:"<<pt.x<<' '<<pt.y;*/
    POINT pt;
    GetCursorPos(&pt);
    HWND h=GetForegroundWindow();
    ScreenToClient(h,&pt);
    pt.x/=8;pt.y/=16;
    return pt;
}
void rectangle(int lcx,int lcy,int rcx,int rcy,int colorinside){
    SetPos(lcx,lcy);
    rcx*=2;
    for(int i=1;i<=abs(lcy-rcy);i++){
        color(-1,colorinside);
        for(int i=1;i<=abs(rcx-lcx);i++)cout<<' ';
        cout<<'\n';
	}
}
void Hollowcircle(int a,int b,int r,int fgc,int bgc,int degree,float precision,char fill){//空心圆
    if(fgc>=0)color(fgc,bgc);
    for(float i=0;i<degree;i+=precision){float X,Y;Y=a+Sin(i)*r;X=b+2*Cos(i)*r;SetPos(X,Y);cout<<fill;}
    color(white,black);
}
void Fillcircle(int a,int b,int r,int fgc,int bgc,float precision,char fill){//实心圆 0.01(精度)
    if(fgc>=0)color(fgc,bgc);
    for(float i=a-r;i<=a+r;i+=precision){float dis=sqrt(r*r-(i-a)*(i-a))*2;for(float j=b-dis;j<b+dis;j+=precision){SetPos(j,i);cout<<fill;}}
    color(white,black);
}
int main(){
	/*HWND hwnd=GetForegroundWindow();
    ShowWindow(hwnd,SW_NORMAL);
	#define SW_HIDE 0
	#define SW_NORMAL 1
	#define SW_MAXIMIZE 3
	#define SW_SHOWNOACTIVATE 4
	#define SW_SHOW 5
	#define SW_MINIMIZE 6
	获取当前时间
	SYSTEMTIME sys;
	GetLocalTime(&sys);
	printf("%4d年%02d月%02d日 %02d:%02d:%02d\n\n",sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute,sys.wSecond);*/
	srand((unsigned)time(NULL));
	SetConsoleTitle("");
	color(white,0);
	appear(0);
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
原文