"does not name a type" error for a file

Nov 10, 2013 at 2:15pm
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 );
Nov 10, 2013 at 2:27pm
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 );
}
Nov 10, 2013 at 2:33pm
yes! that worked! thanks :D
Topic archived. No new replies allowed.