Link to home
Start Free TrialLog in
Avatar of bobbygordon
bobbygordon

asked on

help on writing to a file.

I'm relatively new to C++, and was wondering how it was possible to write to a created temp file, so that my program can read from it when my program loads so it can gain information written to the file.
ASKER CERTIFIED SOLUTION
Avatar of andysalih
andysalih

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andysalih
andysalih

this is how you would read it back in

ifstream fin("filename.txt");
int number;
char letter, word[8];
fin >> number;fin >> word;


hope that helps

andy

Avatar of bobbygordon

ASKER

What header file would i need to include that contains this ofstream and fout?
This's header file:

#include <fstream.h>

I just increased the points...

Is there a way to write and recieve this data, to and from a database as opposed to just a text file?

Or is there a way to use the text file as a database?
A technicality: the header file should be <fstream> - it puts the declarations in the std namespace.

There are many ways to read and write to a database.  It will probably (almost certainly) entail more work than using a textfile.  If you intend to distibute your application, you'd also need to distribute the database. The methods you use will depend on the database you intend to use, and depending on the amount/type of info it might be a complete overkill.

You already are using the text file as a database - it's just a very primitive and non-standard one.

If you still want to go down the database path (which would be a good idea if you're storing lots of info), you'll need to post more details.
For the details that I gave, this helped me understand the concept fairly well.

Thanks,
-Bobby Gordon