Unknown error

I am getting an error I do not know how to fix
Here is my code
#include<iostream>
#include<vector>
#include<fstream>
#include<cstdlib>
#include<string>
#include"account.h"
using std::cout;
using std::string;
using std::fstream;
using std::ifstream;
using std::vector;

class application{
private:

ifstream accountRead("account.dat");

if(!accountRead){
cerr << "Cannot locate file needed to be opened";
exit(1);
}
vector<accountSetup> a;

public:

int main(){
cout<<"Hooray!";
return 0;
}
};

here is the error:
1>c:\users\chris\documents\visual studio 2008\projects\assignment 5\assignment 5\application.h(17) : error C2059: syntax error : 'string'
1>c:\users\chris\documents\visual studio 2008\projects\assignment 5\assignment 5\application.h(19) : error C2059: syntax error : 'if'
1>c:\users\chris\documents\visual studio 2008\projects\assignment 5\assignment 5\application.h(19) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body

Does anyone know what this is from

Last edited on
C++ is not like Java, go read the tutorial on this site on how to write a program.
You are writing executable code inside the class' body, which you can't do. main should be a global function, not a class member
actually I wrote it this way because my teacher wants us to have an application class. This is not the main class here are all three pages of my code:
[b]application.h[/b]
#include<fstream>
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include"account.h"
using std::cout;
using std::string;
using std::fstream;
using std::ifstream;
using std::vector;

class application{
private:
ifstream accountRead("account.dat");
vector<accountSetup> a;

public:

int main(){
cout<<"Hooray!";
return 0;
}
};
[b]main.cpp[/b]
#include"application.h"
#include<iostream>
using namespace std;

int main(){

application app;
return app.main();

}
account.h
#include<iostream>
#include<string>
using std::string;

class accountSetup{
private:
string account_code;
string first_name;
string last_name;
double balance;
public:
accountSetup(string init_account, string init_first, string init_last, double init_balance):
account_code(init_account), first_name(init_first), last_name(init_last), balance(init_balance){};
};


the code works fine until I add in the ifstream
Last edited on
I did not write the code like java I just did not post the other 2 pages just the one giving me the error
Last edited on
I do see what you mean though bazzy so I just moved it into the main function that is inside the application class it works now thanks.
Topic archived. No new replies allowed.