Archived

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

Sketchy

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

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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?

Share this post


Link to post
Share on other sites