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

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

thanks again

This question has already been answered. Start a new discussion instead.