Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ios::bin for numerical data? 1

Status
Not open for further replies.

aaadetos

Programmer
Nov 21, 2004
54
US
I have a table of data, which is read from an input file; the code ignores the 1st 2 lines of the input file, "input.txt" [explanatory header text], then processes the numerical data and writed results to an output file. Do i need to specify that binary data is being written to have meaningful results in my output file? or will i get meaningful results, with my text data?
 
That depends on how you write data to the file.

For a text file
Code:
int myint = 10; file << myint;
This will get you a text file containing two characters '1' and '0', which any text editor (or human) would be able to read.

For a binary file
Code:
int myint = 10; file.write(&myint, sizeof myint);
This will get you a file containing probably 4 bytes with the values 0x00 0x00 0x00 0x0A, which is basically a direct copy of the memory used to store the integer inside the program.
Such files are not readily readable by text editors or humans.

> or will i get meaningful results, with my text data?
Text files are generally preferred.
- you're not tied to your program. Sometimes, simply changing compilers and recompiling the code can mess up your ability to read binary files.
- you can read the output - making validation much easier
- you can use other tools to search / filter / process the information, if the host program lacks that particular feature. Say for example importing a data set into excel.
- you can easily post information in an email / website / document without relying on having the program.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top