tags:

views:

820

answers:

4
+1  Q: 

C++ fstream error

I learning c++, started learning File Handling today. but getting a error when runinng this code

#include <iostream>
#include <fstream.h>

using namespace std;

    int main()
    {
        fstream file;
        file.open("test.txt",ios::in|ios::out)

        file.close();

        return 0;
    }

Gets error

Cannot open include file: 'fstream.h': No such file or directory

Whats Wrong?

+6  A: 

Change your include to:

#include <fstream>

It is a standard library, and you are trying to point it to a non existing header file.

Yuval A
+2  A: 

For standard C++ includes, don't use the .h extension:

#include <fstream>
Ferdinand Beyer
A: 

I Changed it . but getting a other error now

missing ';' before identifier 'file'

Whats wrong now -.-

WoW
Exactly as the compiler says. This line is missing its terminating ';':file.open("test.txt",ios::in|ios::out)
Charles Bailey
It's interesting: The error message is actually bad if you're not used to it. He would have figure it out if it said: missing ';' after 'ios::out)'.
+4  A: 

Missing semicolon:

 file.open("test.txt",ios::in|ios::out)

shoud be:

 file.open("test.txt",ios::in|ios::out);
anon