[Dev-C++] how to do file and streams
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: chromatonus 7. <chr...@ho...> - 2002-05-13 01:17:06
|
hi, here is my program that is supposed to do the following:
Enter a series of records from the keyboard, each record consisting of a
two-word name and an integer,
example MEG RAM 23, as one entry
The program will keep a count of the number of entries. After the last one
is entered, enter a "sentinel" code, some string that will indicate that the
data has been completely entered.
Then the data will be saved to a file in the format of
#data name # name #.......
Then the data will be read from the file and displayed on the screen, one
entry per line.
#include "apstring.h"
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
int main()
{
apstring name1, name2, x, check;
ifstream infile;
infile.open("stuff.dat");
int n;
cin.ignore(80,'\n');
getline(cin,x);
check = "end";
while(x!=check)
{
infile >> name1 >> name2 >> n >> "\n";
cin.ignore(80,'\n');
getline(cin, x);
}
infile.close();
getch();
ofstream xfile;
xfile.open("stuff.dat");
getch();
xfile.close();
}
I don't know how to do the ofstream part, and I don't know whether I
actually saved the data in a file, and how to access the file and display
it? Would you please tell me how to do that, thank you!
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
|