Reading in Strings

Hey everyone.

I was wondering if anyone could help me on a project that I'm working on. It's an exam grader. Basically, I have to write a program that grades a certain number of student's exams by comparing a string of letters to another string in a .txt file.

The file is set up like so:

bccbbadbca
bccaadbada
bccbbabbca
[...]

Where the first line in the file is the key to the exam and the rest are the students' answers.

My question, then, is how do I get my program to read in the first line as the key, then compare it to the rest of the lines?

Would I set the first line into an array, then use a loop to compare?

It's not much, but here's what I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>

using namespace std;

int main()
{

   ifstream fin;
   fin.open ("grade_data.txt");



   return 0;
}
Declare a string or char Array[] to hold the answers.
1
2
string correct;
string student;



Now, read the strings from the file and compare.
1
2
3
4
5
6
7
fin>>correct;   //read correct answer

while(fin>>student)
{
     compare(correct,student); //compare is what you want to do 
     .........
}
That easy, huh? Okay, well, thanks!
Topic archived. No new replies allowed.