reading and writing to binary files in c++ , in The Originals style.

in programming •  7 years ago 

Program Body

#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
class theOriginals{
char name[500];
int saireline;
public:
theOriginals(){
strcpy(name,"enter name of Original");
saireline =1000;}
theOriginals(char *name,int saireline){
strcpy(this->name,name);
this->saireline=saireline;
}
void whichoriginal(){
cout<<"this is "<<name<<" Mikelson and its sires are about "<<saireline<<endl;
}
};
int main(){
theOriginals original("elijah",4003);
fstream file("originals",ios::binary|ios::in|ios::out|ios::trunc);
if(!file.is_open()){
    cout<<"Error occured while opening the file"<<endl;
}else{
file.write((char*)&original,sizeof(theOriginals));
file.seekg(0);
theOriginals vamp("klaus",100000);
vamp.whichoriginal();
original.whichoriginal();
}
}

The originals 

its an american drama serial of vampires.

Made in

source

I hope you guys liked it

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

los archivos binarios son muy interesantes ya que sin ellos no fueramos lo que somos ahora, con el simple hecho de solo traducir datos

Zbrdst