HELP WITH ERROR PLEASE!!!

Alright, so I only have one error and I'm having some trouble tracking down why.

Its where I declare the 3-dimensional vector. Take a look please:

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 "stdafx.h"
#include <iostream>
#include <string>
#include <vector>

using namespace std; //STD library

int main()
{
	vector<int>::const_iterator iter;  //My variables
	vector<string> studName;         //
	vector<char> corrAns;            //
	vector<char> studAns;            //
	vector<int> numCorr;             //
	char correctAns;                 //Fairly
	char studentAns;                 //Self
	string nameStud;                 //Explanitory
	int numStud = 0;                 //
	int questions = 0;               //

	cout << "How many questions will be asked?" << endl; //How many questions to score
	cin >> questions;   //cin num of questions
	studAns.resize(questions); //Resizing Vectors...
	corrAns.resize(questions); // Because its just good programming procedure

	for(int x=0; x<questions; x++) {  //FOR loop to populate correct answers in vector
		cout << "Enter the answer for question " << x+1 << "[A,B,C,D]: " << endl; //cout question
		cin >> correctAns;  //cin answer
		corrAns.push_back(correctAns);  //pushing each answer into vector
	}

	cout << "Enter the number of students to test: " << endl; //asking for number of students to test
	cin >> numStud;  //cin num of students
	studName.resize(numStud);  //resize studName vector
	numCorr.resize(numStud);   //resize numCorrect vector
	


	vector< vector<char> > studentAnswers = (numStud, vector<char>(questions)); //Multi-dimensional vector to keep track of students, answers, percentage.

	for(int i=0; i<numStud; i++) {    //FOR loop to populate names of students being tested
		cout << "Enter the name of student " << i + 1 << ": " << endl;  //cout question
		cin >> nameStud;   //cin name of students
		studName.push_back(nameStud);  //push back each name into vector
		vector<char> row;  //vector position
		
		for(int j=0; j<questions; j++) {   //FOR loop to populate each students answers
			cout << "Enter the answer for question " << j+1 << ": " << endl;  //cout question
			cin >> studentAns;   //cin answer
			row.push_back(studentAns);  //push back name into vector
		}

		studentAnswers.push_back(row);  //push back answer into vector
		row.clear();  //call in destructors
	}

	for(int k=0; k<numStud; k++) {  //FOR loop for students correct answers
		cout << studName[k] << " was correct on the following questions: "; //cout correct?
		
		for(int l=0; l<questions; l++){  //FOR loop to compare and output ans
			if (studentAnswers[k][l] == corrAns[l]) { //compare
				cout << l << " ";  //cout questions correct
				numCorr[k] += 0;  //counter
			}
		}

		cout << endl;  //spacer
		cout << "for a total of " << numCorr[k] << " answers." << endl; //total correct answers
		cout << "And a percentage of " << ((questions / numCorr[k]) * 100) << "%." << endl << endl;  //percentage correct
	}

	system("pause"); //system pause
	return 0; //return
}


The error is :
 
error C2440: 'initializing' : cannot convert from 'std::vector<_Ty>' to 'std::vector<_Ty>'


Thanks for any help or opinions!!!
Last edited on
What line is the error on (the compiler should tell you)?

EDIT: Look at line 39. Are you trying to construct your variable studentAnswers? If so you should be aware that the syntax for calling a constructor is this:
MyClass VarName(arguments here);
and not

MyClass VarName = (arguments here);
as you have done.

Regards
-Xander314
Last edited on
Line 39 in OP. Thanks.

**EDIT**

Alright, will check this out. Thanks a lot Xander.
Last edited on
Okay - see my post above; edited.
Last edited on
Well Xander,

That got it to compile but it crashes. Right after inputting student questions, it iterates once through the next FOR loops, then crashes.

Any thoughts?
What IDE are you using? When running the Visual Studio debugger, it usually tells you which exception was thrown.

Regardless of your IDE, I suggest you set a breakpoint and step through with a debugger to find out which line causes your crash.
Alright. Well, I have everything compiled and running, but it looks like I'm going to have to do some type casting to make it run correctly.

Thanks for the help and take care.
Okay then... Be careful with casting. You should most likely avoid C style casts (and indeed most casts if possible :P).
What types are you intending to cast between?
Topic archived. No new replies allowed.