tags:

views:

452

answers:

4

Hello,

I am getting an ofstream error in C++, here is my code

int main () {
  offstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}

error from Dev-C++ 10

C:\devp\main.cpp aggregate `std::ofstream OutStream' has incomplete type and cannot be defined

Thanks in advance

A: 

I think it is a simple spelling mistake offstream instead of ofstream.

Naveen
still the same....
Can you post the exact code you are compiling? OutStream is not defined in the code posted here.
Naveen
+1  A: 

Probably, you are including the wrong header file. There is a header <iosfwd> that is used for header files that need to reference types from the STL without needing a full declaration of the type. You still are required to include the proper header <iostream> in order to use the types in question.

1800 INFORMATION
Almost certainly.
Daniel Earwicker
+2  A: 

You can try this:

#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}
Viet
A: 

The file streams are actually defined in <fstream>.

anon