fstream and reading from a file
Does anyone know how I would go about getting decimal numbers from a document using fstream. I am using the fstream::get()
function and it is not actually retrieving the information from the file.
any help would be appreciated
thanks
NextGenGamer
I assume that, by "decimal", you mean something like 3.14159. All you have to do is extract from the stream into a floating-point variable. So let''s say you have a float or double called a. Just do this: myfile >> a; At least, I think that''s right.
I tried using the fstream::read() function but it''s not reading the data that is in the file. I have a 2-d array of int''s that i am storing in a text file so that another program can read them. They are being stored as characters I belive but when you look at the text doc they show up as their ascii representations. I want to be able to take those characters and read them back into my program. However, the function is not reading the characters I want it to.
It sounds, then, like your file is binary, not text. If it were text, all data would be human-readable and separated by whitespace of some sort. And I know nothing about binary reading using fstream, since I always use the C standard library for that. So...anybody want to tackle this one?
By the way, not all platforms use ASCII for character encoding. So, you call those funky characters a "numerical representation" [of a value] or something similarly generic.
By the way, not all platforms use ASCII for character encoding. So, you call those funky characters a "numerical representation" [of a value] or something similarly generic.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement