"does not name a type" error for a file

The following code gives me a error that says "error: 'afile' does not name a type"


1
2
3
4
5
6
#include<iostream>
#include<fstream>
#include<conio.h>
#include<string>
std::fstream afile;
afile.open("file.dat", ios::out | ios::in );
Do you have a main() function?
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>

int main()
{
    std::fstream afile;
    afile.open("file.dat", std::ios::out | std::ios::in );
}
yes! that worked! thanks :D
Topic archived. No new replies allowed.