Hi,
I am working on a small application, just to practise File I/O.
The program creates a text document, named by the user, and then it adds both a string & an integer value to the file.
Here is the code wich creates the file:
Code:
char data_file[11]="unset";
{
cout<<"\n **First Run,\n\n *The program needs a source file, \n\n *Please enter source file name(max 10 char): ";
cin.get();
cin.getline(data_file,11,'\n');
ofstream data_stream_pointer("Agent_Data_Loc.txt");
data_stream_pointer<<data_file; // just to be able to find
//the map named by the user
strcat(data_file, ".txt");
ofstream data_stream(data_file);
data_stream<<"Inside 1";
The string value of data_stream_pointer is equal to the name of data_stream(wich is set by the user). I needed this in order to let the program find the text file wich was named by the user.
But the problem is, that I need to let the program extract an integer value FROM the file(named by the user), in this case I need to find the 1 inside data_stream. Is there any way to find and extract it? And how do I let the program detect if a file exists?