Need to read 4 bytes into a long int format. Both inFileDrs and outFileDrs are in ios::binary form. Is this the correct way to do this?

The original piece of code was

var tableCount = reader.ReadUInt32();
unsigned long int tableCount, firstFilePos;
	inFileDrs >> tableCount;
	outFileDrs << tableCount;

Edited by MasterGberry: n/a

6 Years
Discussion Span
Last Post by MasterGberry

The code you've posted is both technically and syntactically valid. Whether it works properly or not depends on how you've defined inFileDrs and outfileDrs and how you use tableCount and firstFilePos elsewhere in your code.

My only concern is that you didn't initialize tableCount and firstFilePos, you only declared them. Others will debate this statement, but it's not really wrong. It is, however, not very reliable and definitely not advisable. You really should initialize EVERY variable when you declare it. That way, you know where you're starting with it and aren't hoping it's uninitialized value will be useful to you.

Edited by Fbody: n/a


Ok, i will intialize them, here is how i opened up the infile and outfile

At the moment I want to be able to just take the pieces of this file and read them and maybe do some edits, i am not sure how the integrity of the program will work, but if u think i did this right syntactically then I am hoping it will work.

ifstream inFileDrs(_orgDrsPath, std::ios::in | std::ios::binary);	
ofstream outFileDrs(newDrsName, std::ios::out | std::ios::binary);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.