Hi there, I have a question about a really simple program. The code below doesn't work, the compiler comes back with "fatal error C1083: Cannot open include file: 'ofstream': No such file or directory":

#include <iostream>

#include <ofstream>

using namespace std ;

int main( )

{

ofstream myfile("newfile.txt") ;

myfile << "This file contains this sentence.\n" ;

myfile.close() ; 


}

if I instead replace

#include <ofstream>

with

#include <fstream>

it's all good.
I thought that if I want to create a file and input some data in it ofstream was enough, or if I wanted to read from a file I had to use ifstream. fstream, I thought, needs to be used only if I want to read and write...
Any suggestion? thanks

Recommended Answers

All 4 Replies

Well I always use fstream in my includes for file I/O.

ok, thanks for that

>> 'ofstream': No such file or directory":

The C++ header files are listed in this Reference.

Brilliant mitrmkar,
thanks for that, I see, I was trying to use a header file that in fact doesn't exist!

thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.