WoW
WoW

Reputation: 923

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?

Upvotes: 1

Views: 2212

Answers (3)

anon
anon

Reputation:

Missing semicolon:

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

shoud be:

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

Upvotes: 4

Ferdinand Beyer
Ferdinand Beyer

Reputation: 67207

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

#include <fstream>

Upvotes: 2

Yuval Adam
Yuval Adam

Reputation: 165340

Change your include to:

#include <fstream>

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

Upvotes: 7

Related Questions