Staredit Network > Forums > Technology & Computers > Topic: need help: reading from a file in C++
need help: reading from a file in C++
Sep 24 2009, 8:37 pm
By: EzDay281  

Sep 24 2009, 8:37 pm EzDay281 Post #1



I'm trying to write a few programs, and they all involve reading files.
Everything I can find online either deals only with reading text files, or else outright confuses me.
I've got my program opening a file, making a new one and writing some dummy text to it, but what I can't figure out is how to actually do anything with the one opened.
Farty showed me some code that would take a file, print its hex contents into the console, and showed me how to print to a different file, instead, but...
Farty's used FILE*s, whereas everything I've been reading on the topic uses i/o/fstreams. I have no idea what the difference between these is, and which I "should" be using... but they require I use different functions and such, which means that following Farty's code would cause me as much trouble as just continuing from where I am.

Post has been edited 1 time(s), last time on Sep 24 2009, 9:06 pm by EzDay281.



None.

Sep 24 2009, 10:27 pm Doodle77 Post #2



If you're writing C++, you should be using iostreams (as you are).
To read binary data from an istream you use its read() method
Code
istream a;
char buf[256];
a.open("file.bin",ios::in|ios::binary);
a.read(buf, 256);




None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[04:15 am]
DarkenedFantasies -- you eat lots of beans
[03:46 am]
IskatuMesk -- how do i get gas
[11:43 pm]
Moose -- you don't
[10:06 pm]
Zoan -- how do i get minerals
[2026-4-14. : 11:45 pm]
ClansAreForGays -- Anyone wanna played Skewed StarCraft?
[2026-4-14. : 12:07 am]
Vrael -- NudeRaider
NudeRaider shouted: Vrael ranting still is though
you're a gentleman and a scholar, thank you
[2026-4-13. : 10:07 pm]
NudeRaider -- ya why phone people when you can just write letters
[2026-4-13. : 9:37 pm]
IskatuMesk -- I have never and will never own a phone
[2026-4-13. : 9:15 pm]
NudeRaider -- Vrael ranting still is though
[2026-4-13. : 9:14 pm]
ClansAreForGays -- anticapitalism isnt edgy anymore
Please log in to shout.


Members Online: Vrael, O)FaRTy1billion[MM]