Original Post
I've been working teaching myself C++ for awhile now, I'm working on file streams in binary mode right now. My read and write functions are below. I'm going to be writing and reading custom objects. What i'm having trouble with is finding the best, most dynamic way to write these and return the information retrieved back to my main function. The ways I know how to do this are, in main() obj temp = read(); or setting a point to hold the memory address of the variable returned. I'm pretty sure theres an easier, simpler way to do this but I'm at a loss right now. I'd prefer not to use a global variable. obj read(int num) { obj temp; ifstream infile; infile.open("DATA.DAT", ios::binary); infile.seekg( num*sizeof(Int) ); infile.read( reinterpret_cast(&temp), sizeof(temp) ); return temp; } void write(obj temp) { ofstream outfile("DATA.DAT", ios::binary); outfile.write(reinterpret_cast(&temp), sizeof(temp) ); }