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

Started by
7 comments, last by Sketchy 21 years, 10 months ago
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!
Advertisement
Have you included the header file?

Joakim Asplund
http://megajocke.cjb.net
Joakim Asplundhttp://megajocke.y2.org
That would be "I included iostream and fstream.h"

=)
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.
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]
Joakim Asplundhttp://megajocke.y2.org
Since the program isnt too long, just post the whole thing up here.

-------------------
The Reindeer Effect
Insomniac Software
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]
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?
[ source ] ... code goes here ... [ /source ] minus the spaces.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers

This topic is closed to new replies.

Advertisement