|
-
Jul 25th, 2005, 12:02 PM
#1
Thread Starter
Hyperactive Member
[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.
-
Jul 25th, 2005, 01:08 PM
#2
Frenzied Member
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.
-
Jul 25th, 2005, 02:59 PM
#3
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|