我是新來的C++,但有半年的Java se/ee7工作經驗。C++矢量多值
我想知道如何把3個值到vector<string>
例如:vector<string, string, string>
或只是vector<string, string>
避免3個載體的使用。
vector<string> questions;
vector<string> answers;
vector<string> right_answer;
questions.push_back("Who is the manufacturer of Mustang?");
answers.push_back("1. Porche\n2. Ford \n3. Toyota");
right_answer.push_back("2");
questions.push_back("Who is the manufacturer of Corvette?");
answers.push_back("1. Porche\n2. Ford \n3. Toyota \n4. Chevrolette");
right_answer.push_back("4");
for (int i = 0; i < questions.size(); i++) {
println(questions[i]);
println(answers[i]);
if (readInput() == right_answer[i]) {
println("Good Answer.");
} else {
println("You lost. Do you want to retry? y/n");
if(readInput() == "n"){
break;
}else{
i--;
}
}
}
如果可能,我想使用類似questions[i][0] questions[i][1] questions[i][3]
的東西。
C++與Java非常不一樣。不要陷入思考的陷阱中,事情是相似的。 –