【发布时间】:2014-10-05 20:21:41
【问题描述】:
所以我这里有这段代码:
std::cout << "Here's Question 2 now for " << char(156) << "200" << endl;
Sleep(2000);
PlaySound(TEXT("Millionaire/£100Play.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
std::cout << "In maths, which of these numbers is not referred to as a square number?" << endl;
Sleep(2000);
std::cout << "A: 0" << endl;
Sleep(2000);
std::cout << "B: 1" << endl;
Sleep(2000);
std::cout << "C: 2" << endl;
Sleep(2000);
std::cout << "D: 4" << endl;
Sleep(2000);
answerQues2:
std::cout << "So, A, B, C or D?";
std::cin >> answer2;
if (answer2 == "C" || answer2 == "c")
{
std::cout << "That's correct, you've won " << char(156) << "200!" << endl;
PlaySound(TEXT("Millionaire/£100correct.wav"), NULL, SND_FILENAME);
Sleep(2000);
}
现在,代码本身不是问题。这本质上是一个带有问题的测验,然后是 4 个答案(A、B、C 和 D)。现在,为了真正提出更多问题,您必须进入代码本身并经历一个漫长的过程来编辑所有内容。我想制作一个文本文件,您可以在文本文件中编辑问题和答案,从而替换代码中的所有内容(例如,如果我想更改 Q1,我可以打开文本文件,替换问题以及何时我加载程序,问题会改变)。我怎么能做到这一点?
【问题讨论】:
-
“我怎么能做到这一点?” - 编写代码。如果您迷失了任何一点,请提出问题。但一如既往,首先谷歌。
-
@KarolyHorvath 当我说“我怎么能做到这一点”时,我的意思是我必须在代码方面做什么?
-
抽象(
class表示问题)、存储容器(list<Question>)、文件处理(ifstream::open、文件解析)... -
当然还要决定你将使用什么文件格式。
-
第一步,您可以创建一个类似于
bool AskQuestion(int Nr, int Score, string Question, string AnswerA, string AnswerB, string AnswerC, string AnswerD, char CorrectAnswer);的函数,然后通过减少参数数量来改进它。
标签: c++ file function text external