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