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.
[2026-6-19. : 9:57 am]
Oh_Man -- makes me wonder if SEN knows anything about the topic
[2026-6-19. : 9:57 am]
Oh_Man -- artosis dropped pretty interesting vid: https://youtu.be/EqZHB8Blra4
[2026-6-18. : 5:01 pm]
Ultraviolet -- :wob:
[2026-6-17. : 6:15 am]
RexyRex -- :wob:
[2026-6-16. : 6:18 am]
IskatuMesk -- me when sick af
[2026-6-16. : 5:45 am]
NudeRaider -- Ultraviolet
Ultraviolet shouted: unless you're a euro weirdo
seems plausible: [01:55 am] dumbducky -- real dad hours who up
[2026-6-16. : 2:45 am]
Ultraviolet -- unless you're a euro weirdo
[2026-6-16. : 2:45 am]
Ultraviolet -- "[08:55 pm] dumbducky -- real dad hours who up" better question, who's already down at 8:55pm?
[2026-6-16. : 12:55 am]
dumbducky -- real dad hours who up
[2026-6-15. : 7:17 pm]
NudeRaider -- why not both?
Please log in to shout.


Members Online: Moose