fstream Tutorial

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

fstream Tutorial

 
1
  #1
Jun 2nd, 2004
  1. File I/O
  2. With C++ Fstream

Intro

File handling is as simple as writing in a book, much easier to modify and
find. It's so simple people get confused with it :-). Welcome to the world of file handling.

We will use the c++ fstream classes to do our file handling. So, what is a file? A file is just a bunch of bytes stored on a hardisk. Some have a specific structure others dont. Files are used to save info so that it can be retrived later for use. [I dont think you will want to save 100 people's address in memory will you].

Types of Files

Actually there are only two. Text files and binary files. In text files data is stored as readable chars and binary file are in machine language. So if you output abc123 to a text file you will see abc123 but in a binary file you may see only a bunch of black blocks if you use notepad. The binary files are smaller in size.

Fstream.h

fstream.h provides simultaneous input and output through ifstream, ofstream and fstream.

  1. ifstream - open the file for input
  2. ofstream - open the file for output
  3. fstream - open the file for input/output/both

Writing to a file

Relatively very simple.

Steps:
  1. Declare an ofstream var.
  2. Open a file with it.
  3. Write to the file (there are a couple of ways.)
  4. Close it.

Eg Program 1.1

  1. #include <fstream.h>
  2.  
  3. void main
  4. {
  5. ofstream file;
  6.  
  7. file.open("file.txt"); //open a file
  8.  
  9. file<<"Hello file\n"<<75; //write to it
  10.  
  11. file.close(); //close it
  12. }

Methods for Writing to a file

The fstream class is derived from the iostream classes, so you can use ofstream variables exactly how you use cout. So you can use the insertion (<<) operator and the put().

  1. Usages:
  2.  
  3. file<<"string\n";
  4. file.put('c');

Reading from a file

Almost the same.

Steps:
  1. Declare an ifstream var.
  2. Open a file with it.
  3. Read from the file(there are a couple of ways.)
  4. Close it.

Eg Program 1.2

  1. #include <fstream.h>
  2.  
  3. void main
  4. {
  5. ifstream file;
  6. char output[100];
  7. int x;
  8.  
  9. file.open("file.txt"); //open a file
  10.  
  11. file>>output; //write to it
  12. cout<<output; //result = Hello file
  13. file>>x;
  14. cout<<x; //result = 75
  15.  
  16. file.close(); //close it
  17. }

Methods for Reading a file

The fstream class is derived from the iostream classes, so you can use fstream variables how you use cin.So you can use the extraction (<<) operator and the put().

  1. Usages:
  2.  
  3. file>>char *; //ie an array
  4. file>>char; //single char
  5. file.get(char); //single char
  6. file.get(char *,int); //read a string
  7. file.getline(char *,int sz);
  8. file.getline(char *,int sz,char eol);

Notes:

1. The file handles can be used like:

  1. ofstream file("fl.txt");
  2. ifstream file("fl.txt");

You will use the constructor for opening a file.I would not recommend using this not because it works less well or anything but in most cases it will improve code clarity and prevent errors when you are handling multiple files. If a file handle is used more than once without calling a close() in between them there will be errors. This is just provided for info sake if you need to use it in a hurry or in something small.

2. Never ever declare a fstream variable globally. It is a bad habit. If you forget to close it next time you run the program it will show access errors to the C: drive (or which ever drive you use) and you will have to restart the computer. Declare them within funtions or classes and close them when their use is over.

3. If you are doing databases or any file handling for that matter never put any file i/o into classes. It will simply complicate debugging and you may also open a single file multiple times with difffrent objects at the same time. This is definitely not what we want. Classes are only to be used when you have to minimal file i/o but still I recommend you use normal funtions.

4. ifstream stands for input stream and can only be used for input.

5. ofstream stands for output stream and can only be used for output.

6. Any variable declared with ifstream,ofstream or fstream is called a file handle.

That wraps up the simple very stuff. You will not use them much unless you are working with text files or in a small project. Now we will move on to fstream which is more flexible and will be most used. It's easy if you look at it logically.

Dynamic file access

The file streams we discussed have a limitation, they can only do input or output at a time. fstream provides us with a way to read, write randomly without having to close and reopen the file. It has great flexibility involving a bit more work with returns being ten fold. Hey, you cant have everything for free (what fun would it be if everything was handed to you).

Lets look at how a file can be opened with fstream.

Program Example 1.3

  1. void main()
  2. {
  3. fstream file;
  4.  
  5. file.open("file.ext",iso::in|ios::out)
  6.  
  7. //do an input or output here
  8.  
  9. file.close();
  10. }

Notice anything new? The ios::--- are attributes which define how a file should be opened.

  1. List of Attributes
  2.  
  3. ios::in open file for reading
  4. ios::out open file for writing
  5. ios::app open for writing,add to end of file(append).
  6. ios::binary Binary file
  7. ios::nocreate do not create the file,open only if it exists
  8. ios::noreplace open and create a new file if the specified file does not exist
  9. ios::trunc open a file and empty it.(Boom, all the data is gone,if any)
  10. ios::ate goes to end of file instead of the begining

Notes
  • The default mode is text mode when a file is opened
  • By default if a file does not exist,a new one is created
  • Multiple attributes can be specified at a time seperated by ...|...|...
  • All attributes start with an ios:: (as if you dint notice it,but still let me hammer it)
  • These attributes can be used with ifstream and ofstream but of course ios::in wont work with ofstream and similarly ios::out wont .............
  • File byte location start from zero (like in arrays)


Now we know how to open a file with fstream. Cool, now come read and write.

Reading and Writing with fstream

The two funtion are exactly similar in usage and simple to understand

  1. file.write(char *,int); //for writing
  2. file.read(char *,int); //for reading (gee...:D)

Until now we have only been able to use strings and ints to write/read. Most databases will want to store data in structures or classes. If we had to write a seperate function to split and write each member, brrr horrors. C++ goes to be very nice and provides us with a way to write entire classes or structures with little work

[/CODE]
struct x
{
int i;
char a;
char s[10];
}data;

file.write((char*)&data,sizeof(x));
file.read((char*)&data,sizeof(x));
[/CODE]

Hold on, what the heck is the char * thingy???.

That's called typecasting. Quite an interesting subject actually. It means converting one data type to another. Here it is converting struct x into a char pointer and it's address is passed to the funtion. If anybody wants to know more, well tell!

The rest is simple. You pass the size of the structure which can be found out by using sizeof();

Eg:

  1. cout<<"\nInt:"<<sizeof(int);
  2. cout<<"\nFloat:"<<sizeof(float);
  3. cout<<"\nChar:"<<sizeof(char);

Now instead of going more yack yack I show you an example which should explain a lot more. Sigh "A picture is worth a thousand word, source is worth a million bytes"

Example Program 1.4

  1. #include <fstream.h>
  2.  
  3. struct contact
  4. {
  5. char name[10];
  6. int age;
  7. }
  8.  
  9. struct address
  10. {
  11. char city[10];
  12. char country[10];
  13. }
  14.  
  15. class DtbRec
  16. {
  17. private:
  18. contact cnt;
  19. address adr;
  20.  
  21. public:
  22. void getdata();
  23. void dispdata();
  24. };
  25.  
  26. /*
  27.   I will give you a bit of work, make the funtions getdata() and dispdata()
  28.   It's easy and not worth for me to bother with now :-}
  29. */
  30.  
  31. void DtbRec::getdata() //get user input
  32. {
  33.  
  34. }
  35.  
  36. void DtbRec::dispdata() //display to screen
  37. {
  38.  
  39. }
  40.  
  41. //This program is not tested, have fun fixing errors, if any
  42. //I am a taos programmer so dont expect anything major
  43. //Typing mistakes are not errors
  44. //This was done off the cuff and not even compiled once
  45.  
  46. void main()
  47. {
  48. DtbRec xRec; //temp rec
  49. fstream fl_h; //file handle
  50. char ch;
  51. int num;
  52.  
  53. fl_h.open("database.dtb",ios::in|ios::out|ios::binary);
  54.  
  55. do
  56. {
  57. cout<<"\n\nFstream Dtb\n"
  58. <<"\n1.Add records"
  59. <<"\n2.View records"
  60. <<"\n3.Modify records"
  61. <<"\n4.Exit"
  62.  
  63. <<"\n\tEnter Choice:";
  64.  
  65. cin>>ch;
  66.  
  67. if(ch == '1') //we are dealing with chars not ints
  68. {
  69. //Adding a rec
  70.  
  71. fl_h.seekp(0,ios::end); //will disscuss this later,this sets the file write pointer to
  72. //the end of a file.
  73. xRec.getdata(); //Get some data from the user
  74.  
  75. fl_h.write((char*)&xRec,sizeof(DtbRec);
  76.  
  77. }
  78. else if(ch == '2')
  79. {
  80. //View recs
  81.  
  82. fl_h.seekg(0,ios::beg); //will disscuss this later,this sets the file read pointer to the
  83. //begining of a file.
  84. num = 0;
  85. while(!fl_h.eof()) //will disscuss this later,it check if the file's end has been reached
  86. {
  87. n++;
  88. fl_h.read((char*)&xRec,sizeof(DtbRec);
  89.  
  90. cout<<"\nRecord No["<<num<<"]\n";
  91. xRec.dispdata(); //Show the user all the data present
  92. }
  93. }
  94. else if(ch == '3')
  95. {
  96. //Modify me colors ;-)
  97.  
  98. cout<<"Enter the record no(starts at 0):";
  99. cin>>num;
  100.  
  101. fl_h.seekg(num*sizeof(DtbRec),ios::beg); //move the read pointer to where the rec is
  102. fl_h.read((char*)&xRec,sizeof(DtbRec); //read it
  103. xRec.dispdata(); //Show the info
  104. xRec.getdata(); //Let the user change the info
  105.  
  106. fl_h.seekp(num*sizeof(DtbRec),ios::beg); //move the write ponter this time
  107. fl_h.write((char*)&xRec,sizeof(DtbRec); //overwrite with new info
  108.  
  109. //yahoo,modification done.I have seen too many people who just
  110. //cant get modification .It's so simiple I just cant get why they just cant
  111. //get it ;-)
  112. }
  113. }
  114. while(ch != '4');
  115.  
  116. fl_h.close(); //close the file
  117. cout<<"\nEnd of Program";
  118. }

Got more doubts now than what was cleared? Good, doubts are the first step towards knowledge. (If you happen to be of an opinion that a teacher should explain everything, sorry it's just not my style. I want thinking students not tape recorders)

Note:
  • Records start at byte zero. I said this once and I will say it again.(Dont forget user friendlyness though.)
  • read() and write() can be used to write both classes and structures to the file in the same way.
  • Always know where you are before you start reading or writing to a file or move the pointer to the area of work.
  • The read pointer and write pointer are separate. So move the correct pointer if you want fstream to work.
  • Always close the file when it's use is over.
  • Always perform checks when necessary or appropriate. fstream has a number of buit-in ones for you :-)
  • Never open a new file with a file handle without calling close().
  • Remember, with structs and classes their size is always fixed so finding the exact location of a record can be done mathematically.


------------------------- PART II -------------------------

Random File Access


With fstream we work with 2 file pointers, read and write. By moving these pointers we go access any part of the file at random. See below:

  1. Reading
  2. 1.seekg(); //move the read pointer in bytes
  3. 2.tellg(); //returns where the read pointer is in bytes
  4.  
  5. Writing
  6. 1.seekp(); //move the write pointer in bytes
  7. 2.tellp(); //returns where the write pointer is in bytes

Both tellp() and tellg() don't take any parameters but return where the pointer location in bytes.

  1. Eg.
  2. int rp = file.tellg();
  3. int wp = file.tellp();

The seek pointers take 2 parameters

  1. Eg.
  2. file.seekg(0,ios::beg);

  1.  
  2. List of seek attributes
  3.  
  4. ios::beg move from the beginning of the file
  5. ios::end move from the end of the file
  6. ios::cur move from current location of the file

Note:
  • ios::beg is default. I recommend you still pass it where ever you use it.
  • Negative numbers can be used with ios::cur & ios::end.(not ios::beg figure it out)

  1.  
  2. Part II
  3. Databases & Security
  4. (Based on a true story of a database)

Intro


This is another area people find difficulty. I figured it out myself without any help what so ever. I also learned file handling a year before my classmates by looking at an elder's text which contained only vague descriptions so I guess my eagerness to learn had something
to do with it. I have always loved computers and programming. I fell in love with QBasic the moment I saw it. C++ stole my heart then. Ah, programming is a part of my soul.

And even when I got my own text book nothing what so ever was mentioned about random file access except a short and vague description about the 2 functions and the options. There was no reference what so ever about locating individual records. I can't guess why! Reminds me of a saying "when old, one forgets how it is to be young". That maybe a cause :D.

[oh, this reminds me, almost every comp guy/gal I know works late at night. I do too when I don't have much time in the mornings. We should stop this. Never work in the dark without enough light, nor stay up too late. If your eyes feel slightly sleepy,SLEEP. No more than 1:30 AM at the most, I am thankful I been able to do most of this]

Locating Individual Records

Problem area. Let start at the beginnings. Ever seen a graph paper ?.It has a lot of tiny, small, medium and large sized squares. Also each is being made from the tiniest square. What that got a do with files? Well when you use databases you will almost always use structures and they are always the same size (in that particular database). That means like in the program in Part I all the records are with that one class and when you write it to a file it will still be the same size even if you filled it or not. It's like your water bottle. Whether it's full, half or even empty it will always
take up the same space in your bag. Get it?

How do you find the size of any data type ?Easy.

  1. Size_Of_Data_Type = sizeof(Data_Type); //sizeof is a reserved keyword in C++.

Ok, how will that help us find a record? Well all records are of the same size, they start at zero. They can be thought of as an array too and the concept is similar to how you use normal pointers.

Eg. A struct is 20 bytes in size. The first rec starts at byte zero, the second at byte 20, the next at byte 40 ...... and so on

Eg. Program 2.1

  1. file.seekg( Rec_no * sizeof(Data_Type),ios::beg);
  2. file.read((char*)&rec_var,sizeof(Data_Type));
  3.  
  4. file.seekp( Rec_no * sizeof(Data_Type),ios::beg);
  5. file.write((char*)&rec_var,sizeof(Data_Type));

Simple as that.

Note:
  • This can be use with ios::beg,ios::cur and ios::end
  • When read() or write() is called the appropriate pointer is moved automatically to the next record or rather by a number of bytes as passed to it(that's the sizeof(Data_Type))

I think now you get random access. How about finding the total number of records in a database?

Eg. Program 2.2

  1. file.seekg(0,ios::end); //move to the end of the file
  2.  
  3. int fl_sz = file.tellg(); //tell me where you are, partner( pointer ) !
  4. int total_no_rec = fl_sz/sizeof(Data_Type);
  5.  
  6. file.seekg(0,ios::beg); //move to the beg of the file
  7.  
  8. cout<<"There are "<<total_no_rec<<" (s) in this database ";

We divide the total file size by the size of the structure to find the number of record. Simple maths eh?

That's it you have full knowledge of how to handle fstream. Now all you need is creativity, so use it. I won't tell you all, so think. Knowledge can be gained from others but wisdom only from yourself (and from God).

Ah, I love this. Here is some work for you.
  1. Re-write the example program to include random reading, writing, and modification on multiple databases. [Put in error checks and don't allow the user to read or modify a rec which does not exist]
  2. Find a way to write a whole single dimensional array of a struct to a file with just one write statement. [No hints, re-read this paper if you have to]
  3. Deletion. Add a way to allow a person to delete an existing record.
  4. [One way to do it, copy all the records except the one to be deleted to another temp file, open the database with ios::trunc and copy the records from the other temp file.]

Error Checking

These are some funtions that help to keep track of errors in your database if any

  1. Error Funtions
  2.  
  3. good() returns true if the file has been opened without problems
  4. bad() returns true if there were errors when opening the file
  5. eof() returns true if the end of the file has been reached

All are member funtions and are used as file_handle.errror_funtion()

Eg.

  1. char ch;
  2. ifstream file("kool.cpp",ios::in|ios::out);
  3.  
  4. if(file.good()) cout<<"The file has been opened without problems;
  5. else cout<<"An Error has happend on opening the file;
  6.  
  7. while(!file.eof())
  8. {
  9. file>>ch;
  10. cout<<ch;
  11. }

You should have understood what those funtions are for. Implement them when you do you file handling. good() should be called after opening a file to see it has been opened properly. bad() is the opposite of good().

Encryption

Aha, any decent database program must encrypt its files. Just open up any of the files from the example programs with notepad and you will be able to see the text. We definitely don't want people to see that.

With encryption you can scramble the text so people can read it. Now there are a lot of encryption schemes and a lot of other methods for protecting data. I will just show you a couple of methods.

Binary Shift

The simplest of all. In this you increase or decrease a char by a number.

  1. void b_shif(char *s,int n)
  2. {
  3. for(int i=0;s[i]!=0;i++)
  4. {
  5. s[i] += n;
  6. }
  7. }

XOR

Another type of encryption. Exclusive-OR encryption, is almost unbreakable through brute force methods. It is susceptible to patterns, but this weakness can be avoided through first compressing
the file (so as to remove patterns). This encryption while extremely simple, is nearly unbreakable.

  1. int xor(char *string, char *key)
  2. {
  3. int l=0;
  4. for(int x=0; string[x]!='\0'; x++)
  5. {
  6. string[x]=string[x]^key[l];
  7. l++;
  8. if(l>=strlen(key)) l=0;
  9. }
  10. return 0;
  11. }

Encrypt an entire structure

  1. void struct_enc_xor(char *str,char *key,int sz)
  2. {
  3. int l=0;
  4. for(int x=0; str[x]!='\0'; x++)
  5. {
  6. str[x]=str[x]^key[l];
  7. l++;
  8. if(l>=strlen(key)) l=0;
  9. }
  10. return 0;
  11. }

Use it exactly how you used read().

Eg.
struct_enc_xor((char*)&cRec,"password",sizeof(DtbRec));

Exit

Encryption is a very interesting topic. A lot of research has gone into it. If you are interested there are lot of pages on the web which describe encryption and various schemes. Then there is stenography,
the art of hiding info in any file like text within a bitmap or an mp3. Have fun researching.
Last edited by happygeek; Nov 12th, 2006 at 11:40 am. Reason: Formatting, spelling etc
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: fstream Tutorial

 
0
  #2
Jun 7th, 2004
Now here's a printer friendly version(has a few fixes to part I)

http://www.polarhome.com:793/~xlock/txt/fstream.txt
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,040
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 127
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: fstream Tutorial

 
0
  #3
Jun 7th, 2004
Cool. In addition, DaniWeb users can always use the Thread Tools dropdown and then select Printable Version for any thread
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 19
Reputation: Pikachu is an unknown quantity at this point 
Solved Threads: 0
Pikachu's Avatar
Pikachu Pikachu is offline Offline
Newbie Poster

Re: fstream Tutorial

 
0
  #4
Aug 10th, 2004
Hello!
I have a little question. Lets say, I have a file called word.txt and it contains 100 over words.
How do I add a new word and SAVING it so I can use this word from this file in future?

Thanks
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: fstream Tutorial

 
0
  #5
Aug 21st, 2004
Quite simple really,just open word.txt with ios::app (append) added to the options when opening the file.That will automaticaly put the file pointer to the end of the file and you can just write to it normally.

Another way is to open the file and use filehandle.seekp(0,ios::end); to move the pointer to the end of the file and then write the output you want to the file and it will still be at the end.

Checks the tut for the list of options,I covered them there.

Btw,then close the file when you exit or are finished with using it.There you go a new word was added to the file.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: fstream Tutorial

 
0
  #6
Sep 2nd, 2004
A little update.My site URL is now:
http://xlock.hostcubix.com/
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 2
Reputation: Jubulani is an unknown quantity at this point 
Solved Threads: 0
Jubulani Jubulani is offline Offline
Newbie Poster

Re: fstream Tutorial

 
0
  #7
Sep 7th, 2004
Interesting tutorial, however I did notice a few errors here and there.
if you output abc123 to a
text file you will see abc123 but in a binary file you may see only a bunch of black
blocks if you use notepad
I just tested this, and its not true. If you output "abc123" to a binary file, you will see "abc123" when you open that file in notepad (or any text editor). The difference between binary mode and text mode is that text mode replaces '\n' with something appropriate for the operating system you are using. Different OS's store linebreaks differently: IIRC Windows uses "\n\r" pairs, unix uses '\n' and macs use '\r'. Text mode will translate between these automatically for you, binary mode will not.

If a file handle is used
more than once without calling a close() in between them there will be errors
If you open an ofstream object with a file name, and write output to it, then call open() on the same file stream without closing it, there will be no errors. The call to open() will close the file you were writing to and just open another file. Similarly:
If you forget to close it [the fstream object]
next time you run the program it will show access errors to the C: drive (or which ever drive
you use) and you will have to restart the computer.
The destuctor of an fstream object will close any file handles for you. The last program I made left an open file handle at the end of the program. There was no problem with this, as when the destructor of the ofstream object was called, it closed the file handle automatically. Destructors are guaranteed to be called for all objects at the end of their life (for a global object at the end of the program) so there is no problem leaving file handles open. The only possible problem with this is if your program causes a seg fault or something similar, and the OS has to close it unexpectedly. In that case you have more problems than open file handles though. I do so love the fstream library. Its so hard to f*ck thinks up with it.

It was a very interesting tutorial though. You did a lot with fstream that I wouldn't have thought of.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: fstream Tutorial

 
0
  #8
Sep 8th, 2004
True enough,about certain char being translated in the text mode.But let me remind that file<<"abc123" is a string.Try doing file<<"abc"<<123<<(char)123;

See what happens, one forgets and assumes a bit somethimes.

If you open an ofstream object with a file name, and write output to it, then call open() on the same file stream without closing it, there will be no errors. The call to open() will close the file you were writing to and just open another file. Similarly:
Try doing that with the fstream object.Also if an fstream object is declared in the global scope and it's not closed when you run the program again some access errors might be shown. A lot of my friends had this problem when they did their projects.Never declare anything global unless it's necessary.

This may not be true on diffrent compilers (or even the same one's diffrent versions).That could have happened due to a lot of reasons.But it a good practice to alway close a file handle before you exit .I just said something which might possibly happen, .

I love the fstreams too.Thanks so much Jubulani.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 2
Reputation: Jubulani is an unknown quantity at this point 
Solved Threads: 0
Jubulani Jubulani is offline Offline
Newbie Poster

Re: fstream Tutorial

 
0
  #9
Sep 10th, 2004
Oops, my mistake. Calling 'open()' on an open file stream does cause errors. Sorry about that. And, true, always better safe than sorry.

Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: fstream Tutorial

 
0
  #10
Sep 11th, 2004
Yea, prevention is better than cure
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC