code assistance: the << after outputFile in the writeStudents function is showing an error. Please advise.

Write your question here.

I need to access the file inputFielName.txt however the computer said asertion failed. I guess the program is not reading the file. Please assist.
here is the code.

/*---------------------------------------------------

Name: Christian Molto

Student ID: R50666934

COP 1334 - Introduction to C++

Spring 2013 - MW 7:50PM - 10:05PM

Assignment # 8

Plagiarism Statement

I certify that this assignment is my own work and that I
have not copied in part or whole or otherwise plagiarised
the work of other students and/or persons.

----------------------------------------------------------*/

#include <iostream>
#include <fstream>
#include <string>
#include <vector>


using namespace std;

enum Status {PASSING, FAILING};

struct Student
{
string name;
double grade1, grade2, grade3, average;
Status status;
};

void readStudents (vector<Student>&, string);

void writeStudents (vector<Student>, string);

string getInputFileName();

string getOutputFileName();

int main()
{


//your code goes here
vector<Student> students;

string inputFileName, outputFileName;

inputFileName = getInputFileName();

outputFileName = getOutputFileName();

readStudents(students, inputFileName);

writeStudents(students, outputFileName);


system("PAUSE");

return 0;
}

string getInputFileName()
{
string inputFile;

cout << "What is input file name?\n";

cin >> inputFile;

return inputFile;
}

string getOutputFileName()
{
string outputFile;

cout << "What is output file name?\n";

cin >> outputFile;

return outputFile;
}

void readStudents(vector<Student>& students, string inputFileName)
{
int currentValue;

unsigned count;

double grade1, grade2, grade3, average;

string status;

ifstream inputFile;

count = 0;

students[count].average;

students[count].grade1;

students[count].grade2;

students[count].grade3;

students[count].average = (students[count].grade1 + students[count].grade2 + students[count].grade3) / 3;

inputFile.open(inputFileName);

if (!inputFile.fail())
{
while(inputFile >> currentValue)
{
inputFile >> currentValue;
}

inputFile.close();

}
else
{
cout << "Error!\n";
}
}

void writeStudents(vector<Student> students, string outputFileName)
{
unsigned count;

double grade1, grade2, grade3, average;

string name, status;

ofstream outputFile;

count = 0;

students[count].grade1;

students[count].grade2;

students[count].grade3;

students[count].average;

students[count].average = (students[count].grade1 + students[count].grade2 + students[count].grade3) / 3;

outputFile.open(outputFileName);

outputFile << "Name" << "\t" << "Grade1" << "\t" << "Grade2" << "\t"
<< "Grade3" << "\t" << "Average" << "\t" << "Status" << endl;

if(!outputFile.fail())
{
for(unsigned count = 0; count < students.size(); count++)
{
outputFile << students[count].name << endl;
}

outputFile.close();

}
else
{
cout << "Error!!\n";
}
Last edited on
Please use code tags
http://www.cplusplus.com/articles/z13hAqkS/

Students is a struct so you need to specify what data member of the struct you are trying to access.

for example outputFile << students[count].name << endl;
Last edited on
I need to access name, grades 1-3, average, and status. Please advise on this.
Topic archived. No new replies allowed.