Link to home
Start Free TrialLog in
Avatar of Splint
Splint

asked on

getting data from a txt file

I have a very basic game that I am working on and want to use a read only text file to save basic dat (character name, stats etc) I can make the file as I want but cannot figure out how to get said data back out.
                                      -Splint
ASKER CERTIFIED SOLUTION
Avatar of Exceter
Exceter
Flag of United States of America image

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 boludazo
boludazo

Yes, or use the old C stuff:

#include <stdio.h>

main()
{
FILE *inputfile;
int i = 200;
char read[200];
char filename[] = "c:\\myfile.txt";

if ( (inputfile = fopen(filename, "r") ) != NULL)
{

 while (fgets(read,i,inputfile))
        {
           
        cout >> read; //This while statement is for printing every line of the file.      
           
        }
}
}
Yes, or use the old C stuff:

#include <stdio.h>

main()
{
FILE *inputfile;
int i = 200;
char read[200];
char filename[] = "c:\\myfile.txt";

if ( (inputfile = fopen(filename, "r") ) != NULL)
{

 while (fgets(read,i,inputfile))
        {
           
        cout >> read; //This while statement is for printing every line of the file.      
           
        }
}
}
>> Yes, or use the old C stuff:

This is the C++ topic area not the C topic area. :-)
Avatar of Splint

ASKER

Alright Thanks a lot, I'll look into it

ps: I say read only because I make the file and then delete it when new data is added. read only will prevend at least the most passive of tampering