I'm making a quiz program with vectors and I keep running into trouble. I keep getting getline errors in my program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
using namespace std;
int main()
{
//declare variables
vector<string> qNa;
string general;
double questions = 0.0;
int multChoice = 0;
int getQuest = 0;
int getChoice = 0;
char choiceAnswer = 'a';
double correct = 0;
string p2Answer = "";
//find number of questions and multiple choice answers
cout << "Enter number of questions: ";
getline (cin, general);
stringstream(general) >> questions;
cout << "Enter number of multiple choice answers: ";\
getline (cin, general);
stringstream(general) >> multChoice;
while (multChoice > 26)
{
cout << "Please enter a number lower than 26: ";
getline (cin, general);
stringstream(general) >> multChoice;
}
//get questions and answers
while(getQuest < questions)
{
cout << getQuest + 1 << ". ";
getline(cin, qNa [getQuest] [getChoice]); //error C2784
while(getChoice <= multChoice)
{
getChoice++;
cout << choiceAnswer << ". ";
choiceAnswer++;
getline(cin, qNa [getQuest][getChoice]); //error C2784
}
cout << "Enter answer: ";
getline(cin, qNa [getQuest][getChoice + 1]); //error C2784
getQuest++;
choiceAnswer = 'a';
}
getQuest = 0;
getChoice = 0;
//test p2
while (getQuest < questions)
{
cout << getQuest + 1 << ". " << qNa [getQuest][getChoice] << endl;
while (getChoice <= multChoice)
{
getChoice++;
cout << choiceAnswer << ". " << qNa [getQuest][getChoice] << endl;
getline (cin , p2Answer);
if (p2Answer == qNa [getQuest][getChoice]) //error C2784 error C2676
{
correct++;
}
}
getQuest++;
}
cout << "\nYou are " << questions / correct * 100 << "% correct.\n";
return (0);
}
|
These are the error codes
Error 1 error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'char' c:\users\arnoldr\documents\generic solution\generic\quiz.cpp 40 Generic
Error 2 error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3 arguments - 2 provided c:\users\arnoldr\documents\generic solution\generic\quiz.cpp 40 Generic
Error 8 error C2784: 'bool std::operator ==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'std::string' c:\users\arnoldr\documents\generic solution\generic\quiz.cpp 65 Generic
Error 38 error C2676: binary '==' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator c:\users\arnoldr\documents\generic solution\generic\quiz.cpp 65 Generic