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-8-06. : 2:41 am]
Oh_Man -- i used to play TF2 competitive in that clan, and also was PR manager (ie: i wrote all the website posts)
[2026-8-06. : 2:41 am]
Oh_Man -- another fun fact iaguz actually joined the clan i was part of - Frenetic Array
[2026-8-06. : 2:40 am]
Symmetry -- Human memory is a fragile, fallible thing
[2026-8-06. : 2:39 am]
Oh_Man -- i realised all his shit was halluc and i wiped out his measly army of fake hallucs and he called GG - yeah thts wat actually happened damn false memory strikes again
[2026-8-06. : 2:38 am]
Oh_Man -- i was zerg, the toss guy did a bunch of hallucinates, and i was like, welp, i guess i'm dead, but i have that mindset of never giving up, so attacked him anyway, then tht was wen
[2026-8-06. : 2:38 am]
Oh_Man -- coz i was actually a zerg main, so wat ACTUALLY happened was a complete reverse of this
[2026-8-06. : 2:37 am]
Oh_Man -- i found an old comment of mine i actually think the idra thing over-ride my own memory
[2026-8-06. : 2:22 am]
Symmetry -- was it idra
[2026-8-06. : 1:52 am]
NudeRaider -- Oh_Man
Oh_Man shouted: and i went on to win the tournament, and a pair of steelseries headphones. i even reember how i won the final match - hallucinated a fck-tonne of units and my opponent thought i had way more than he did and GGed
classic
[2026-8-05. : 2:56 pm]
Oh_Man -- long story short - patience is a virtue!
Please log in to shout.


Members Online: RIVE, Roy, Symmetry