Last active
May 30, 2016 12:11
-
-
Save dbasilioesp/1d723dacd960128a2fb6d68c40d2dfe6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
int x; | |
ifstream infile; | |
infile.open("silly.dat", ios::binary | ios::in) | |
infile.read(&x, 7); // reads 7 bytes into a cell that is either 2 or 4 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Person | |
{ | |
char name[50]; | |
int age; | |
char phone[24]; | |
}; | |
int main() | |
{ | |
Person me = {"Robert", 28, "364-2534"}; | |
Person book[30]; | |
int x = 123; | |
double fx = 34.54; | |
ofstream outfile; | |
outfile.open("junk.dat", ios::binary | ios::out); | |
outfile.write(&x, sizeof(int)); // sizeof can take a type | |
outfile.write(&fx, sizeof(fx)); // or it can take a variable name | |
outfile.write(&me, sizeof(me)); | |
outfile.write(book, 30*sizeof(Person)) | |
outfile.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment