push_back error

So, I'm writing a program that is supposed to take in a text file with a bunch of different types of questions and ask the user them. Kind of like a trivia game.
The text file is formatted a certain way so that the first 3 letters indicates what kind of question the number is how many points and then the question, followed by the correct answers. like -

FIB 1 What is the name of Han Solo's ship Millennium _____ : Falcon
MC3 1 The young Jedi Knight, Anakin Skywalker, becomes who in Star Wars? : Darth Vader : Ben Kenobi : The Emperor
TOF 1 Han was the first person in the moves to be kissed by Leia : False

It's supposed to read each line, determine what kind of question it is and then store it into a container of "TriviaQuestions". I've most of it I think but when I'm trying to use push_back it gives me no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=TriviaQuestions, _Alloc=std::allocator<TriviaQuestions>]" matches the argument list

I feel like I"m doing something really simple wrong but I can't seem to find it. 47
I have a .h and .cpp file as well.
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
  Main -
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include "TriviaQuestions.h"

using namespace std;

int main()
{
	ifstream triviaFile;
	string file, line;
	vector <TriviaQuestions> questions; 

		triviaFile.open("Questions.txt");
		cout << "File Opened";
	
	while (getline(triviaFile, line))
	{
		if (true)
		{
			string ln = string(0);
			string statement = ln.substr(4, ln.length() - 4);

			if (ln.substr(0, 3) == "FIB")
				questions.push_back(new fillInBlank(statement));
		}
	}
	
}

.h -
#include <string>
#include <vector>
using namespace std;
class TriviaQuestions
{

public:
	TriviaQuestions();
	TriviaQuestions(const string&);
	 
	virtual int getMax(); 
	virtual int askQuestion() ;

protected: 
	int points;
	string question;
	string answer;
};

//Fill In The Blank

class fillInBlank: public TriviaQuestions
{
private: string answer;
public:
	fillInBlank();
	
	int getMax(); 
	int askQuestion();
	fillInBlank(const string&);
	
};

//3-Part Multiple Choice
class multipleChoice3 : public TriviaQuestions
{
private: 
	string answer;
	vector<string> options;
public:
	multipleChoice3();
	multipleChoice3(int, string);
	int getMax();
	int askQuestion();
	multipleChoice3(const string&);;
};

//4-part multiple choice
class multipleChoice4 : public TriviaQuestions
{
private:
	string answer;
	vector<string> options;
public:
	multipleChoice4();
	
	int getMax();
	int askQuestion();
	multipleChoice4(const string&);
};

//True or False

class trueOrFalse : public TriviaQuestions
{
private:
	string answer;
public:
	trueOrFalse();
	trueOrFalse(const string&);
	
	int getMax();
	int askQuestion();
};

//numeric-type question

class numeric : public TriviaQuestions
{
private:
	string answer;
public:
	numeric();
	numeric(const string&);
	int getMax();
	int askQuestion();
};


#include "TriviaQuestions.h"
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

TriviaQuestions::TriviaQuestions()
{
	points = 1;
	question = "Unknown";
}
TriviaQuestions::TriviaQuestions(const string& statement)
{
	int colon = statement.find(':'); 
	points = statement[0] - '0'; 
	question = statement.substr(2, colon - 2); /
	answer = statement.substr(colon + 2, statement.length() - colon - 2); 

}


int TriviaQuestions::askQuestion()
{
	cout << question;
	string input;

	while (true)
	{
		getline(cin, input);
		if (input == answer)
			return points;
	}
	return 0;
}
//FILL IN THE BLANK
fillInBlank::fillInBlank()
{
	points = 1;
	question = "Unknown";
}


fillInBlank::fillInBlank( const string statement)
{
	int colon = statement.find(':');
	points = statement[0] - '0'; 
	question = statement.substr(2, colon - 2); 
	answer = statement.substr(colon + 2, statement.length() - colon - 2); 

}

int fillInBlank::askQuestion()
{
	cout << question;
	string input;

	while (true)
	{
		getline(cin, input);
		if (input == answer)
			return points;
	}
	return 0;
}
//3-PART MULTIPLE CHOICE

multipleChoice3::multipleChoice3()
{
	points = 1;
	question = "Unknown";
}

multipleChoice3::multipleChoice3(const string& statement)
{
	int answerStart = statement.find(':');
	int answerEnd = statement.find(':', answerStart - 2);

	points = statement[0] - '0';
	question = statement.substr(2, answerStart - 2);
	options = vector<string>(3);

	for (int i = 0; i < 3; ++i)
	{
		if (answerEnd == string::npos)
		{
			options[i] = statement.substr(answerStart + 2, statement.length() - answerStart - 1);
			options[i].erase(remove(options[i].begin(), options[i].end(), '\n'), options[i].end());
		}

		else
		{
			options[i] = statement.substr(answerStart + 2, answerEnd - answerStart - 3);
			options[i].erase(std::remove(options[i].begin(), options[i].end(), '\n'), options[i].end());
		}
		answerStart = answerEnd;
		answerEnd = statement.find(':', answerStart + 1);

	}
	answer = options[0];
}

int multipleChoice3::askQuestion()
{
	cout << "This is a 3-part Multiple Choice question worth" << points << "points" << endl;
	cout << question << endl;

	random_shuffle(options.begin(), options.end()); //Shuffles the answers

	//PRints out the different options
	cout << "A: " << options[0] << endl;
	cout << "B: " << options[1] << endl;
	cout << "C: " << options[2] << endl;

	string input; //User answer

	while (true)
	{
		getline(cin, input);
		if (input == answer)
			return points;
		else
			break;
	}
	return 0;

}
	


//4-PART MULTIPLE CHOICE

multipleChoice4::multipleChoice4()
{
	points = 1;
	question = "Unknown";
}

multipleChoice4::multipleChoice4(const string& statement)
{
	int answerStart = statement.find(':');
	int answerEnd = statement.find(':', answerStart - 2);

	points = statement[0] - '0';
	question = statement.substr(2, answerStart - 2);
	options = vector<string>(4);

	for (int i = 0; i < 4; ++i)
	{
		if (answerEnd == string::npos)
		{
			options[i] = statement.substr(answerStart + 2, statement.length() - answerStart - 1);
			options[i].erase(remove(options[i].begin(), options[i].end(), '\n'), options[i].end());
		}

		else
		{
			options[i] = statement.substr(answerStart + 2, answerEnd - answerStart - 3);
			options[i].erase(std::remove(options[i].begin(), options[i].end(), '\n'), options[i].end());
		}
		answerStart = answerEnd;
		answerEnd = statement.find(':', answerStart + 1);

	}
	answer = options[0];
}

int multipleChoice4::askQuestion()
{
	cout << "This is a 4-Part multiple choice question worth " << points << " points" << endl;
	cout << question;

	random_shuffle(options.begin(), options.end());

	cout << "A: " << options[0] << endl;
	cout << "B: " << options[1] << endl;
	cout << "C: " << options[2] << endl;
	cout << "D: " << options[3] << endl;

	string input;
	while (true)
	{
		getline(cin, input);
		if (input == answer)
			return points;
		else
			break;
	}
	return 0;
}

//TRUE OR FALSE

numeric::numeric()
{
	points = 1;
	question = "Unknwon";
}
//TRUE OR FALSE

numeric::numeric(const string& statement)
{
	int answerStart = statement.find(':');
	points = statement[0] - '0'; //Finds points on the line
	question = statement.substr(2, answerStart - 2); 
	answer = statement.substr(answerStart + 2, statement.length() - answerStart-2);
	answer.erase(remove(answer.begin(), answer.end(), '\n'), answer.end());
}

int numeric::askQuestion()
{
	cout << "This is a numeric question worth " << points << " points";
	cout << endl << question << endl;
	string input;
	while (true)
	{
		if (input == answer)
			return points;
		else
			break;
	}
}


//NUMERIC QUeSTIONS

trueOrFalse::trueOrFalse()
{
	points = 1;
	question = "unknwon";
}

trueOrFalse::trueOrFalse(const string& statement)
{
	int answerStart = statement.find(':');
	points = statement[0] - '0'; 
	question = statement.substr(2, answerStart - 2);
	answer = statement.substr(answerStart + 2, statement.length() - answerStart - 2);
	answer.erase(remove(answer.begin(), answer.end(), '\n'), answer.end());
}

int trueOrFalse::askQuestion()
{
	cout << "This is a True Or False question worth " << points << " points" << endl;
	cout << "A. True" << endl;
	cout << "B. False" << endl;

	string input;
	while (true)
	{
		if (input == answer)
			return points;
		else
			break;
	}

}



To be honest, I don't know if the .cpp part even does what it's supposed to since I can't get it to run.
Any help would be appreciated. Thanks.
Hello Awesomeness,

To star with putting the green check on your message tells everyone that you are finished. You need to edit your post and change the icon.

Posting the mostly complete error message is good, but is does not say what line number or file it is to.

Now it will take more time to load up the program and compile it to see what is going wrong.

Andy
As one file which compiles with no errors (but with warnings):

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
using namespace std;

const auto seed = std::chrono::system_clock::now().time_since_epoch().count();

class TriviaQuestions
{
public:
	TriviaQuestions();
	TriviaQuestions(const string&);

	virtual int getMax() { return 0; }	// TO BE DONE
	virtual int askQuestion();

protected:
	int points;
	string question;
	string answer;
};

//Fill In The Blank

class fillInBlank : public TriviaQuestions
{
private: string answer;
public:
	fillInBlank();

	int getMax() { return 0; }	// TO BE DONE
	int askQuestion();
	fillInBlank(const string&);

};

//3-Part Multiple Choice
class multipleChoice3 : public TriviaQuestions
{
private:
	string answer;
	vector<string> options;
public:
	multipleChoice3();
	multipleChoice3(int, string) {}		// TO DE DONE
	int getMax() { return 0; } // TO BE DONE
	int askQuestion();
	multipleChoice3(const string&);;
};

//4-part multiple choice
class multipleChoice4 : public TriviaQuestions
{
private:
	string answer;
	vector<string> options;
public:
	multipleChoice4();

	int getMax() { return 0;}	// TO BE DONE
	int askQuestion();
	multipleChoice4(const string&);
};

//True or False

class trueOrFalse : public TriviaQuestions
{
private:
	string answer;
public:
	trueOrFalse();
	trueOrFalse(const string&);

	int getMax() { return 0; }	// TO BE DONE
	int askQuestion();
};

//numeric-type question

class numeric : public TriviaQuestions
{
private:
	string answer;
public:
	numeric();
	numeric(const string&);
	int getMax() { return 0; }	// TO BE DONE
	int askQuestion();
};

TriviaQuestions::TriviaQuestions()
{
	points = 1;
	question = "Unknown";
}
TriviaQuestions::TriviaQuestions(const string& statement)
{
	int colon = statement.find(':');
	points = statement[0] - '0';
	question = statement.substr(2, colon - 2);
		answer = statement.substr(colon + 2, statement.length() - colon - 2);

}

int TriviaQuestions::askQuestion()
{
	cout << question;
	string input;

	while (true)
	{
		getline(cin, input);
		if (input == answer)
			return points;
	}
	return 0;
}

//FILL IN THE BLANK
fillInBlank::fillInBlank()
{
	points = 1;
	question = "Unknown";
}

fillInBlank::fillInBlank(const string& statement)
{
	int colon = statement.find(':');
	points = statement[0] - '0';
	question = statement.substr(2, colon - 2);
	answer = statement.substr(colon + 2, statement.length() - colon - 2);

}

int fillInBlank::askQuestion()
{
	cout << question;
	string input;

	while (true)
	{
		getline(cin, input);
		if (input == answer)
			return points;
	}
	return 0;
}
//3-PART MULTIPLE CHOICE

multipleChoice3::multipleChoice3()
{
	points = 1;
	question = "Unknown";
}

multipleChoice3::multipleChoice3(const string& statement)
{
	int answerStart = statement.find(':');
	int answerEnd = statement.find(':', answerStart - 2);

	points = statement[0] - '0';
	question = statement.substr(2, answerStart - 2);
	options = vector<string>(3);

	for (int i = 0; i < 3; ++i)
	{
		if (answerEnd == string::npos)
		{
			options[i] = statement.substr(answerStart + 2, statement.length() - answerStart - 1);
			options[i].erase(remove(options[i].begin(), options[i].end(), '\n'), options[i].end());
		}

		else
		{
			options[i] = statement.substr(answerStart + 2, answerEnd - answerStart - 3);
			options[i].erase(std::remove(options[i].begin(), options[i].end(), '\n'), options[i].end());
		}
		answerStart = answerEnd;
		answerEnd = statement.find(':', answerStart + 1);

	}
	answer = options[0];
}

int multipleChoice3::askQuestion()
{
	cout << "This is a 3-part Multiple Choice question worth" << points << "points" << endl;
	cout << question << endl;

	//random_shuffle(options.begin(), options.end()); //Shuffles the answers
	shuffle(options.begin(), options.end(), default_random_engine(seed));

	//PRints out the different options
	cout << "A: " << options[0] << endl;
	cout << "B: " << options[1] << endl;
	cout << "C: " << options[2] << endl;

	string input; //User answer

	while (true)
	{
		getline(cin, input);
		if (input == answer)
			return points;
		else
			break;
	}
	return 0;
}

//4-PART MULTIPLE CHOICE

multipleChoice4::multipleChoice4()
{
	points = 1;
	question = "Unknown";
}

multipleChoice4::multipleChoice4(const string& statement)
{
	int answerStart = statement.find(':');
	int answerEnd = statement.find(':', answerStart - 2);

	points = statement[0] - '0';
	question = statement.substr(2, answerStart - 2);
	options = vector<string>(4);

	for (int i = 0; i < 4; ++i)
	{
		if (answerEnd == string::npos)
		{
			options[i] = statement.substr(answerStart + 2, statement.length() - answerStart - 1);
			options[i].erase(remove(options[i].begin(), options[i].end(), '\n'), options[i].end());
		}

		else
		{
			options[i] = statement.substr(answerStart + 2, answerEnd - answerStart - 3);
			options[i].erase(std::remove(options[i].begin(), options[i].end(), '\n'), options[i].end());
		}
		answerStart = answerEnd;
		answerEnd = statement.find(':', answerStart + 1);

	}
	answer = options[0];
}

int multipleChoice4::askQuestion()
{
	cout << "This is a 4-Part multiple choice question worth " << points << " points" << endl;
	cout << question;

	//random_shuffle(options.begin(), options.end());
	shuffle(options.begin(), options.end(), default_random_engine(seed));

	cout << "A: " << options[0] << endl;
	cout << "B: " << options[1] << endl;
	cout << "C: " << options[2] << endl;
	cout << "D: " << options[3] << endl;

	string input;
	while (true)
	{
		getline(cin, input);
		if (input == answer)
			return points;
		else
			break;
	}
	return 0;
}

//TRUE OR FALSE

numeric::numeric()
{
	points = 1;
	question = "Unknwon";
}
//TRUE OR FALSE

numeric::numeric(const string& statement)
{
	int answerStart = statement.find(':');
	points = statement[0] - '0'; //Finds points on the line
	question = statement.substr(2, answerStart - 2);
	answer = statement.substr(answerStart + 2, statement.length() - answerStart - 2);
	answer.erase(remove(answer.begin(), answer.end(), '\n'), answer.end());
}

int numeric::askQuestion()
{
	cout << "This is a numeric question worth " << points << " points";
	cout << endl << question << endl;
	string input;
	while (true)
	{
		if (input == answer)
			return points;
		else
			break;
	}
}

//NUMERIC QUeSTIONS

trueOrFalse::trueOrFalse()
{
	points = 1;
	question = "unknwon";
}

trueOrFalse::trueOrFalse(const string& statement)
{
	int answerStart = statement.find(':');
	points = statement[0] - '0';
	question = statement.substr(2, answerStart - 2);
	answer = statement.substr(answerStart + 2, statement.length() - answerStart - 2);
	answer.erase(remove(answer.begin(), answer.end(), '\n'), answer.end());
}

int trueOrFalse::askQuestion()
{
	cout << "This is a True Or False question worth " << points << " points" << endl;
	cout << "A. True" << endl;
	cout << "B. False" << endl;

	string input;
	while (true)
	{
		if (input == answer)
			return points;
		else
			break;
	}

}

int main()
{
	ifstream triviaFile;
	string file, line;
	vector <TriviaQuestions*> questions;

	triviaFile.open("Questions.txt");
	cout << "File Opened";

	while (getline(triviaFile, line))
	{
		if (true)
		{
			string ln = string(0);
			string statement = ln.substr(4, ln.length() - 4);

			if (ln.substr(0, 3) == "FIB")
				questions.push_back(new fillInBlank(statement));
		}
	}
}

Last edited on
Topic archived. No new replies allowed.