• Popular Now

• 13
• 18
• 19
• 27
• 10

Archived

This topic is now archived and is closed to further replies.

OT: Help opening an output file in VC++ 6!!!

This topic is 5761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Ok, here''s a problem thats probably simple, but its driving me completely insane, and I thought some of you C/C++ whizzes would be able to help. 1) I start by creating a "Hello World" console application, using VC++ 6.0 (It''s one of the options when creating a new project). The application is meant to be in C++. 2) I want to add to the application such that it opens a file, prints "You printed hello world" in it, and then closes the file. 3) I included , , and then changed the MAIN function to: int main (...) //can''t remember default params at the moment =P { ofstream test; test.open ("test.txt"); printf ("hello world"); test << "you printed hello world!"; test.close(); return(0); } For whatever reason, this just doesn''t work!!! It says the ofstream is undefined, and then complains about all the test.* calls, so I figured I must be including wrong, or something. I was also getting an error about reaching the end of a preprocessor directive or something. If anyone could do a SIMPLE program for VC++ 6 similar (takes all of 2 minutes) to what I''ve done that actually works, I would be greatful to be able to test it to see if it works on my computer. Thanks in advance!

Share on other sites
Have you included the header file?

Joakim Asplund
http://megajocke.cjb.net

Share on other sites
That would be "I included iostream and fstream.h"

=)

Share on other sites
I''m really rusty with C++, so I might have included it wrong or something, I just used:

#include iostream
using namespace std;

#include fstream.h

I used angle brackets too, but if I put those in, they don''t show up here, but they are in the code.

Share on other sites
I think it is fstream, not fstream.h

(oops the post got mangled when i sent it the first time)
(it was the angle brackets =) )
Joakim Asplund
http://megajocke.cjb.net

[edited by - megajocke on June 10, 2002 12:56:16 PM]

[edited by - megajocke on June 10, 2002 12:57:23 PM]

Share on other sites
Since the program isnt too long, just post the whole thing up here.

-------------------
The Reindeer Effect
Insomniac Software

Share on other sites
Do not put the h at the end of fstream; that is the deprecated header. All new C++ library headers should just have the filename in brackets:

    #include<iostream>#include<fstream>using namespace std;

[edited by - invective on June 10, 2002 1:04:33 PM]

Share on other sites
Cool, I''ll try getting rid of the .h extension later today, and if I still can''t get it working, I''ll post the code.

BTW, how do you get the little white box for code?