Re: [Dev-C++] how to do file and streams
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2002-05-13 08:01:59
|
I think if you include ostream.h and create an object of the ostream class,
then use the .open command you should be ok.
ofstream ofstreamObject; // For managing the text file
ofstreamObject.open( "File1.txt"); // Create and name our text file
ofstreamObject.close();
>From: "chromatonus 712" <chr...@ho...>
>To: dev...@li...
>Subject: [Dev-C++] how to do file and streams
>Date: Mon, 13 May 2002 01:16:58 +0000
>
>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.
>
>
>_______________________________________________________________
>
>Have big pipes? SourceForge.net is looking for download mirrors. We supply
>the hardware. You get the recognition. Email Us: ban...@so...
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_________________________________________________________________
Join the worlds largest e-mail service with MSN Hotmail.
http://www.hotmail.com
|