E
enki
I would like to know how to save and read an array of objects using
stdio.h.
So far I have opened and closed the file but how do I actually put the
data in the file then read it out?
This is what I have...
#include<iostream>
#include<stdio.h>
#include "myvec.cpp"
#include "an.hpp"
int main(){
int lp = 0;
int ag;
int num;
V<anmial*>box; //My personal vector.
while(ag != 0){
anmial *an;
cout<<"The age 0 quits:";
cin>>ag;
cout<<"1)Dog 2)Cat 3)Horse 4)Person:";
cin>>num;
if(num < 1){
an = new dog(ag);
}
if(num == 2){
an = new cat(ag);
}
if(num == 3){
an = new horse(ag);
}
if(num > 3){
an = new person(ag);
}
box=an;
lp++;
}
FILE *ptr;
ptr = fopen("Anmail_Data.dat", "wb");
for(int l = 0 ; l > lp; l++){
//What goes here?
}
fclose(ptr);
return 0;
Later, it how would I read the file?
}
stdio.h.
So far I have opened and closed the file but how do I actually put the
data in the file then read it out?
This is what I have...
#include<iostream>
#include<stdio.h>
#include "myvec.cpp"
#include "an.hpp"
int main(){
int lp = 0;
int ag;
int num;
V<anmial*>box; //My personal vector.
while(ag != 0){
anmial *an;
cout<<"The age 0 quits:";
cin>>ag;
cout<<"1)Dog 2)Cat 3)Horse 4)Person:";
cin>>num;
if(num < 1){
an = new dog(ag);
}
if(num == 2){
an = new cat(ag);
}
if(num == 3){
an = new horse(ag);
}
if(num > 3){
an = new person(ag);
}
box=an;
lp++;
}
FILE *ptr;
ptr = fopen("Anmail_Data.dat", "wb");
for(int l = 0 ; l > lp; l++){
//What goes here?
}
fclose(ptr);
return 0;
Later, it how would I read the file?
}