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();
 writer.Write(tableCount);
unsigned long int tableCount, firstFilePos;
	inFileDrs >> tableCount;
	outFileDrs << tableCount;

Recommended Answers

All 2 Replies

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.

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.