D
Drewdog
I am getting some error messages which I can't figure out their
meaning. I have the code setup, I think it's correct but it doesn't
work. My goal is to get this program to read from a data file and
basically put it into an output file that I can access as a test file.
Here is my header file:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
struct StudRdType
{
int id;
float exam1;
float exam2;
float exam3;
};
StudRdType students;
void ReadRd(ifstream&, StudRdType[]);
void WriteRd(ofstream&, StudRdType[]);
Here is my function file: It is supposed to hit the data file, read it
and save the information. For example the data file looks like:
1111 275 323 432
1342 432 235 532
2343 235 432 234
So the ReadRd function is spoed to read that and save it. I can't get
it do that, im a bit rusty and can't seem to remember how to do this.
This is what I have for the function file (implementation).
#include "stud2.h"
void ReadRd(ifstream& inFile, StudRdType students[])
{
inFile.get(students.id);
while(inFile)
{
inFile >> students.exam1 >> students.exam2 >> students.exam3);
inFile.ignore('\n');
inFile.get(students.id);
}
}
void WriteRd(ofstream& outFile, StudRdType students[])
{
outFile << students.id << students.exam1 << students.exam2 <<
students.exam3 << endl;
outFile.setf(ios::fixed);
outFile.setf(ios::showpoint);
outFile.precision(2);
}
For some reason it isn't working , not sure hwy.. Finally here is my
driver file:
#include "stud2.h"
int main()
{
ifstream inFile;
ofstream outFile;
StudRdType students;
inFile.open("in.data");
outFile.open("out.data");
if(inFile.fail() || outFile.fail())
{
cout << "input or out file opening failed" << endl;
exit(1);
}
ReadRd(inFile, students);
WriteRd(outFile, students);
outFile << "*** END ***" << endl;
return 0;
}
Now here are the errors I get when I run them.. Again my goal is to
read the data file I showed above and print it to an outfile, the exact
same way as it looks.
Errors:
runstud2.cxx: In function `int main()':
runstud2.cxx:40: error: cannot convert `StudRdType' to `StudRdType*'
for
argument `2' to `void ReadRd(std::ifstream&, StudRdType*)'
runstud2.cxx:41: error: cannot convert `StudRdType' to `StudRdType*'
for
argument `2' to `void WriteRd(std:fstream&, StudRdType*)'
stud2.cxx: In function `void ReadRd(std::ifstream&, StudRdType*)':
stud2.cxx:15: error: request for member `id' in `students', which is of
non-class type `StudRdType*'
stud2.cxx:19: error: request for member `exam1' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:19: error: request for member `exam2' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:19: error: request for member `exam3' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:19: error: parse error before `)' token
stud2.cxx:21: error: request for member `id' in `students', which is of
non-class type `StudRdType*'
stud2.cxx: In function `void WriteRd(std:fstream&, StudRdType*)':
stud2.cxx:35: error: request for member `id' in `students', which is of
non-class type `StudRdType*'
stud2.cxx:35: error: request for member `exam1' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:35: error: request for member `exam2' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:35: error: request for member `exam3' in `students', which is
of
non-class type `StudRdType*'
I'm completely Confused.. I am in need of some serious help as I am
eager to learn this stuff and am unsure as to what I'm doing
incorrectly.
Thanks in advance!
meaning. I have the code setup, I think it's correct but it doesn't
work. My goal is to get this program to read from a data file and
basically put it into an output file that I can access as a test file.
Here is my header file:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
struct StudRdType
{
int id;
float exam1;
float exam2;
float exam3;
};
StudRdType students;
void ReadRd(ifstream&, StudRdType[]);
void WriteRd(ofstream&, StudRdType[]);
Here is my function file: It is supposed to hit the data file, read it
and save the information. For example the data file looks like:
1111 275 323 432
1342 432 235 532
2343 235 432 234
So the ReadRd function is spoed to read that and save it. I can't get
it do that, im a bit rusty and can't seem to remember how to do this.
This is what I have for the function file (implementation).
#include "stud2.h"
void ReadRd(ifstream& inFile, StudRdType students[])
{
inFile.get(students.id);
while(inFile)
{
inFile >> students.exam1 >> students.exam2 >> students.exam3);
inFile.ignore('\n');
inFile.get(students.id);
}
}
void WriteRd(ofstream& outFile, StudRdType students[])
{
outFile << students.id << students.exam1 << students.exam2 <<
students.exam3 << endl;
outFile.setf(ios::fixed);
outFile.setf(ios::showpoint);
outFile.precision(2);
}
For some reason it isn't working , not sure hwy.. Finally here is my
driver file:
#include "stud2.h"
int main()
{
ifstream inFile;
ofstream outFile;
StudRdType students;
inFile.open("in.data");
outFile.open("out.data");
if(inFile.fail() || outFile.fail())
{
cout << "input or out file opening failed" << endl;
exit(1);
}
ReadRd(inFile, students);
WriteRd(outFile, students);
outFile << "*** END ***" << endl;
return 0;
}
Now here are the errors I get when I run them.. Again my goal is to
read the data file I showed above and print it to an outfile, the exact
same way as it looks.
Errors:
runstud2.cxx: In function `int main()':
runstud2.cxx:40: error: cannot convert `StudRdType' to `StudRdType*'
for
argument `2' to `void ReadRd(std::ifstream&, StudRdType*)'
runstud2.cxx:41: error: cannot convert `StudRdType' to `StudRdType*'
for
argument `2' to `void WriteRd(std:fstream&, StudRdType*)'
stud2.cxx: In function `void ReadRd(std::ifstream&, StudRdType*)':
stud2.cxx:15: error: request for member `id' in `students', which is of
non-class type `StudRdType*'
stud2.cxx:19: error: request for member `exam1' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:19: error: request for member `exam2' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:19: error: request for member `exam3' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:19: error: parse error before `)' token
stud2.cxx:21: error: request for member `id' in `students', which is of
non-class type `StudRdType*'
stud2.cxx: In function `void WriteRd(std:fstream&, StudRdType*)':
stud2.cxx:35: error: request for member `id' in `students', which is of
non-class type `StudRdType*'
stud2.cxx:35: error: request for member `exam1' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:35: error: request for member `exam2' in `students', which is
of
non-class type `StudRdType*'
stud2.cxx:35: error: request for member `exam3' in `students', which is
of
non-class type `StudRdType*'
I'm completely Confused.. I am in need of some serious help as I am
eager to learn this stuff and am unsure as to what I'm doing
incorrectly.
Thanks in advance!