#include <fstream.h> fails

I want to open and read a file but when I try to build my program it says
"fatal error: fstream.h: no such file or directory"
I am using code::blocks to write code and GNU CPP Compiler and code in c++.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int main()
{
    int x = 0;

    fstream datei("C:\\Users\\Name\\Desktop", ios::in);

    char zeile[200];

    while(datei.getline(zeile,200)){
        if(zeile==a||zeile==e||zeile==i||zeile==o||zeile==u){
            x++;
        }
    }
    datei.close;
    
    return 0;
}
the .h is a c-header file extension that you don't need here, just use #include <fstream>;
incidentally you can also change the other .h header files you're using by dropping the .h at the back and stick a c in front
Thanks! But datei.close is now giveng me an error message :/ :

|21|error: statement cannot resolve address of overloaded function|
That's because date.close is a function, and you forgot to include its parantheses ( type datei.close() )
Last edited on
Oh yeah didnt realise I forgot those
Topic archived. No new replies allowed.