I was wondering if you could save and recover numbers from files. The tutorial didn't really say anything about it. Although it does talk about ASCII.
I was wondering if you could save and recover numbers from files. The tutorial didn't really say anything about it. Although it does talk about ASCII.
you can always use sscanf and sprintf to convert any data to string and when write/read strings using
fgets/fputs (one way)
you can use fprintf/scanf pair directly
or you can use fread/fwrite pair for binary in/out operations if the reading and writing is always performed by the same application on the same platform
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Isn't that C style coding.
Also, either I don't understand you fully, or I didn't explain my question well enough. I have several numbers that I would like to store to a file so that a user can save their game if they don't complete it.
Just one more question, is there a way to create a file if it doesn't already exist?
To start off this article may be of interest to you.
http://www.cplusplus.com/doc/tutorial/files.html
it's pretty basic, and doesn't give examples of writing/reading numbers to/from files, but the functions vart provided should do that. Overall I think it's a pretty good tutorial, it's how I got started with file I/O.
Ahh, sorry, in this case - just open file as a fstream, and then use it as it is any other istream or ostream you use... (You do know how to use cout/cin, do you?)
for converting string to int and vise-versa - you can use stringstream
and of course, if you open file for writing, that does not exists - it is created
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Yes, I do know how to use cin/cout. I will look into that tutorial. Thanks for all the help.