Reputation: 923
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
Reputation:
Missing semicolon:
file.open("test.txt",ios::in|ios::out)
shoud be:
file.open("test.txt",ios::in|ios::out);
Upvotes: 4
Reputation: 67207
For standard C++ includes, don't use the .h extension:
#include <fstream>
Upvotes: 2
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