fstream issue. any ideas?

T

Tom Andrecht

I'm trying to get some information dumped from a program that's giving me
fits, but when i try to use the ofstream class to dump to file, i get a
message from the compiler that it doesn't exist. This is a simple program
for a class (intro to opengl) wich uses only one .cpp file and has included
at the beginning #include <fstream>. the code below is what I know to be
correct for opening and writing to a file, but the ofstream declaration
comes up invalid even though intellisense knows what's going on and gives me
my members lists. could i possibly have a corrupt install? or am i looking
at this crosseyed and my code is wrong? Thanks

ofstream mazestream;
mazestream.open("path.txt", std::ios::app);
for (int i = 0; i < 100; i++)
{
mazestream.write(square);
mazestream.write("\n");
}
mazestream.close();
 
R

Ronald Laeremans [MSFT]

You are missing the following:

using namespace std;

Or of course something a bit more granular which is what I would recommend
for production code.

Ronald Laeremans
Visual C++ team
 
V

Vincent Finn

I'm trying to get some information dumped from a program that's giving me
fits, but when i try to use the ofstream class to dump to file, i get a
message from the compiler that it doesn't exist. This is a simple program
for a class (intro to opengl) wich uses only one .cpp file and has included
at the beginning #include <fstream>. the code below is what I know to be
correct for opening and writing to a file, but the ofstream declaration
comes up invalid even though intellisense knows what's going on and gives me
my members lists. could i possibly have a corrupt install? or am i looking
at this crosseyed and my code is wrong? Thanks

ofstream mazestream;
mazestream.open("path.txt", std::ios::app);
for (int i = 0; i < 100; i++)
{
mazestream.write(square);
mazestream.write("\n");
}
mazestream.close();


'ofstream' is in the 'std' namespace

declare
std::blush:fstream mazestream;

Vin
 
G

Guest

I'm trying to port some old code and have run into the same problem. I'm
usually a VB programmer and it's been 9 years since I've written any C.

I tried putting in the line you suggested towards the top of the first .cpp
file that is called but it did not work. Can you give me a little more
background on where it should go and/or how it should work?

Any help would be greatly appreciated!



Ronald Laeremans said:
You are missing the following:

using namespace std;

Or of course something a bit more granular which is what I would recommend
for production code.

Ronald Laeremans
Visual C++ team

Tom Andrecht said:
I'm trying to get some information dumped from a program that's giving me
fits, but when i try to use the ofstream class to dump to file, i get a
message from the compiler that it doesn't exist. This is a simple program
for a class (intro to opengl) wich uses only one .cpp file and has
included at the beginning #include <fstream>. the code below is what I
know to be correct for opening and writing to a file, but the ofstream
declaration comes up invalid even though intellisense knows what's going
on and gives me my members lists. could i possibly have a corrupt
install? or am i looking at this crosseyed and my code is wrong? Thanks

ofstream mazestream;
mazestream.open("path.txt", std::ios::app);
for (int i = 0; i < 100; i++)
{
mazestream.write(square);
mazestream.write("\n");
}
mazestream.close();

 
C

Carl Daniel [VC++ MVP]

eHaggis said:
I'm trying to port some old code and have run into the same problem.
I'm usually a VB programmer and it's been 9 years since I've written
any C.

I tried putting in the line you suggested towards the top of the
first .cpp file that is called but it did not work. Can you give me
a little more background on where it should go and/or how it should
work?

Any help would be greatly appreciated!

How 'bout a little more information about what you're trying to do and
exectly what errors you're running into?

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top