离奇的……句柄无效……
  • 板块学术版
  • 楼主acwing_cht
  • 当前回复23
  • 已保存回复23
  • 发布时间2020/6/15 13:58
  • 上次更新2023/11/7 00:36:26
查看原帖
离奇的……句柄无效……
247533
acwing_cht楼主2020/6/15 13:58

自己写小程序结果句柄无效了。 小程序不要转载! 大家写在自己的DEVc++就知道会句柄无效了。

#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
#include <conio.h>
#include <windows.h> 
#include <stdio.h>

using namespace std; 

HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

int xrand(int x, int n)
{
	return x + 1 + n;
}

void pos(int x,int y)
{
    COORD posPoint = {x,y};  
    SetConsoleCursorPosition(hOut,posPoint);
}

void my_color()
{
    WORD orange = FOREGROUND_RED|FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_INTENSITY|BACKGROUND_GREEN;
    SetConsoleTextAttribute(hOut,orange);
}

void cyan_choose()
{
    WORD cyan =FOREGROUND_GREEN|FOREGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_BLUE;
    SetConsoleTextAttribute(hOut,cyan);
}

void white_back()
{
    WORD white = FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY;
    SetConsoleTextAttribute(hOut,white);
}

void init()
{
	for(int i = 1; i <= 60; i ++)
		for(int j = 1; j <= 20; j ++)
			if(i == 1 || i == 60 || j == 1 || j == 20)
				pos(i, j), cout << "#", Sleep(1);
}

int main() 
{
	white_back();
	system("color 1F"); 
	SetConsoleTitle("数学生成器");
	init();
	my_color();
	pos(22, 10);
	cout << "欢迎来到数学生成器!" << endl; 
	pos(25, 11);
	cout << "按a继续……";
	char xxx;
	while(xxx != 'a')
	{
		xxx = getch();	
	} 
	system("cls");
	init();
	pos(22, 10);
	int n;
	cout << "数据范围:";
	cin >> n;
	Sleep(1000);
	system("cls");
	init();
	pos(22, 10);
	int x;
	cout << "题目数量:";
	cin >> x;
	Sleep(1000);
	system("cls");
	init();
	pos(22, 10);
	char op;
	cout << "运算符号:";
	cin >> op;
	Sleep(1000);
	system("cls");
	init();
	pos(22, 10);
	cout << "正在生成中……"; 
	freopen("D:\\mymath.out", "w", stdout);
	for(int i = 1; i <= x; i ++)
	{
		srand(i);
		pair<int, int> res;
		
		res.first = rand() % n + 1;
		srand(xrand(x, i));
		res.second = rand() % n + 1;
		
		cout << res.first << ' ' << op << ' ' << res.second << endl;
	}
	fclose(stdout);
	Sleep(1000);
	system("cls");
	init();
	pos(22, 10);
	cout << "生成完毕,";
	Sleep(1000);
	system("cls");
	init();
	pos(18, 10); 
	cout << "请在D盘mymath.out中查看。";
	Sleep(1000);
	system("cls");
	init();
	pos(22, 10);
	cout << "请按任意键继续……";
	char qwq;
	while(qwq == ' ')
	{
		qwq  = getch();
	} 
	
	CloseHandle(hOut);
	
	return 0;
}
2020/6/15 13:58
加载中...