error C2784. getline 3 arguments expected - 2 provided

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
Do you think qNa's size is not zero before you use qNa [getQuest] [getChoice]?
For your getline 's try
cin.getline();

I can't tell the problems with the rest of your code as I'm on a laptop.

Oh yeah!
Why are you doing this?
return(0);
instead of
return 0;
Last edited on
@Eric

I was told not to size the vector. I was told that it expands itself so sizing it would be redundant.

@Ben

I was told you had to put the return value in parentheses for every function so I just do it habitually.
Operations like insert, push_back, erase, will expand the vector.
That does not happend with access, so out of bounds is an issue.

1
2
vector<string> qNa;
getline(cin, qNa [getQuest] [getChoice]);
qNa is a vector,
qNa[K] is a string
qNa[K][L] is a character.

getline wants a string as second parameter.

1
2
	getline (cin, general);
	stringstream(general) >> questions;
¿why are you doing that?

return (0); Those brackets are superfluous.
I'm using stringstream because I read on this site's tutorial to use that so the compiler doesn't get screwed up if someone accidentally enters a character.

I haven't programmed a function for a few months before this, so I forgot exactly what the return instruction was supposed to look like. I decided the brackets would be safe.

Can I make it so all the cells of the vector are strings or do I have to make individual vectors for everything?
Last edited on
Topic archived. No new replies allowed.