Results 1 to 3 of 3

Thread: [RESOLVED]fstream

  1. #1
    Hyperactive Member chuddy's Avatar
    Join Date
    Oct 02
    Posts
    333

    Resolved [RESOLVED]fstream

    I want to carry out some file handling operations and was thinking of using the <fstream.h> library.

    Code:
    #include "stdafx.h"
    #include <fstream.h>
    
    int main(int argc, char* argv[])
    {
      fstream myStream;
      char file1[20] = "testing";
      myStream.open(file, ios:://problem...
    
      return 0;
    }
    2 questions:

    Firstly, my problem manifests itself when i type in "myStream.open"

    From all the reference material and examples that I have seen online I can see that there are only 2 arguments for this function. However, the Visual C++ intellisense is telling me that the signature is actually:

    Code:
    void open (const char*, int, int=filebuf::openprot)
    I am using Windows XP... is this the reason? Also... when I type in "ios" the intellisense does not give me options such as "app" . Instead I have "adjustfield, bad, basefield, bitalloc, bp, clear... etc".

    Secondly, I just wanted to know how come all the examples show that i can use a fstream object without first using the "new" keyword? How come it can be used without instanciation?

    Thanks!
    Last edited by chuddy; Jul 26th, 2005 at 03:47 AM.

  2. #2
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 02
    Posts
    1,037

    Re: fstream

    You probably need a lesson on what new does. When you declare a variable:
    fstream f;
    it is an instance and has a place in memory and automatically deletes itself but...
    fstream* pf=new fstream();
    creates an instance somewhere else in memory and needs to be deleted manually:
    delete pf;
    pf is a pointer to an fstream object and pf in itself is a variable, a local variable.

    I think you want f.open("file.txt", ios::binary | ios::in | ios::out); or
    f.open("file.txt", ios::binary | ios::in | ios::out | ios::app);

    intellisence is trash that's why you don't get a list sometimes.

    I'd help you more with fstream but I don't use it anymore. I use fopen fwrite...instead.
    Last edited by aewarnick; Jul 25th, 2005 at 01:12 PM.

  3. #3
    Hyperactive Member chuddy's Avatar
    Join Date
    Oct 02
    Posts
    333

    Re: fstream

    aewarnick,

    Thanks for the tips

    I ignored the intellisense it's working fine...

    I think I understand what you mean about the "new" keyword as well now. Was thinking that it worked the same way as it did in Java (although thinking about it.. the C++ way actually seems to make more sense now :P)

    Cheers!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •