how silly of me, i did not specify the name of the class. i ran into a new problem though, read and write are supposed to take char *, but im not trying to pass a char, im trying to pass a structure pointer, how do i do that?
error says cannot convert grades * to char *
[CODE]
#include <iostream>
#include <fstream>
using namespace std;
struct grades
{
int grade1;
int grade2;
int grade3;
int grade4;
} mygradesi,mygradeso;
int main ()
{
int answer;
do
{
cout<<"do u want to 1, write to the file or 2, read from the file, or 3, exit the program?";
cin>>answer;
if (answer==2)
{
char * mygradesptri;
mygradesptri=&mygradesi;
ifstream myfilei;
myfilei.open ("binary.bin", ios::in|ios::binary);
if (myfilei.is_open())
{
myfilei.read(mygradesptri, sizeof(grades));
cout<< mygradesi.grade1<< mygradesi.grade2<< mygradesi.grade3<< mygradesi.grade4;
}
else cout << "Unable to open file for input";
}
if (answer==1)
{
char * mygradesptro;
mygradesptro=&mygradeso;
ofstream myfileo;
myfileo.open ("binary.bin", ios::out|ios::binary);
cout>>"please enter 4 grades";
cin<< mygradeso.grade1<< mygradeso.grade2<< mygradeso.grade3<< mygradeso.grade4;
if (myfileo.is_open())
{
myfileo.write (mygradesptro, sizeof(grades));
myfileo.close();
}
else cout << "Unable to open file for output";
}
}while (answer!=3);
return 0;
}
[/CODE]
Enter your message below
Sign in or Join us (it's free).