我有一个类,其中包括一个向量如果字符串,所以我可以有无限的答案(我用这个来研究本质上做模拟测试)。然而,当我创造东西的时候,它试图在矢量中创造价值时会生我的气。我已经尝试了很多方法来使它起作用,但它不能。在类中创建类与矢量
#include <iostream>
#include <vector>
using namespace std;
string input;
class answer {
public:
vector<string> answers;
};
class qANDa {
public:
string question;
answer answers;
string correct;
};
void askQuestion (qANDa bob) {
cout << bob.question;
getline(cin, input);
input[0] = tolower(input[0]);
if (input == bob.correct) {
cout << "Correct!\n";
} else {
cout <<"Incorrect. Study more. Loser.\n";
};
}
vector<qANDa> thingys;
int main(int argc, const char * argv[]) {
qANDa thingy = {"The correct answer is \"A\". What's the correct answer.", {} "A"}
askQuestion(thingys.at(0));
}
我试图把字符串的括号内,我已经使用了括号内括号试过了,我已经把括号内的括号内的字符串,但没有它的工作原理。
您是否尝试将'answer()'而不是{{}'空括号? –
我没有,那工作。感谢您的建议。如果您将其添加为答案,我可以将其标记为正确。 – dunnmifflsys
另外,有没有一种方法可以在定义答案时加入? – dunnmifflsys