#include <bits/stdc++.h> #include <windows.h> #include <conio.h> #include 'config.h' using namespace std;

void gotoxy(short x, short y) { COORD pos; pos.X = x, pos.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); }

void cls() { system("cls"); }

int main() { cout << "Welcome to Q&A!\nInput 'exit' to exit and 'help' to help" << endl;

string cmd;
while (1)
{
	cout << ">>> ";
	cin >> cmd;
	if (cmd == "exit")
	{
		cout << "Bye" << endl;
		break;
	}
	else if (cmd == "add")
	{
		ofstream xout;
		string content, answer;
		getchar();

		while (cls(), cout << "Input: Problem's content: ", getline(cin, content))
		{
			if (content.find('`') != string::npos || content.size() < 1)
			{
				cls();
				cout << "Please input content without '`'" << endl;
				Sleep(1000);
				getch();
				cls();
			}
			else
			{
				break;
			}
		}
		while (cls(), cout << "Input: Problem's answer: ", getline(cin, answer))
		{
			if (answer.find('`') != string::npos || answer.size() < 1)
			{
				cls();
				cout << "Please input answer without '`'" << endl;
				Sleep(1000);
				getch();
				cls();
			}
			else
			{
				break;
			}
		}
		xout.open("problem_list.txt", ios_base::out | ios_base::app);
		xout << '`NEWPROBLEM`\nCONTENT: " << content << "\nANSWER: " << answer << "\nWATIMES: 0\nACTIMES: 0\n`ENDPROBLEM`" << endl;
		xout.close();

		cout << "Successful!" << endl;
		Sleep(1000);
		cls();
	}
	else if (cmd == "init")
	{
		// TODO: 实现“init”命令的功能
	}
	else if (cmd == "help")
	{
		cout << "Input 'exit' to exit, 'help' to help, 'add' to add problem, 'init' to join new problem" << endl;
	}
	else
	{
		cout << "Input help to help" << endl;
	}
}

return 0;
C++ 实现问答系统:增加“init”命令

原文地址: http://www.cveoy.top/t/topic/p2F 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录