passing filename values to classes

Is there any way that you can pass values from your int main function, say content in a file, to a class outside the function?
I tried doing something like this, not my actual code,this would always send me something not in the file.
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
26
27
28
29
30
31
32
33
34
35
36
#include<fstream>
#include<iostream>

class Function
{
private:
inputfile;

public:
int sum;
int x;
int addition();
};
int Function::addition()
{
int sum=0
inputfile>>x
sum= sum+x;
cout<<sum;
}
int main()
{
Function add;
int x;
 string filename;
 ifstream inputfile;
 cout<<filename;

inputfile.open(filename, ios::in)

if (inputfile.is_open())
{
 inputfile>>x;
 add.addition();
 }
}
Functions can have parameters, for example:
1
2
3
4
void function(int parameter)
{
    // "parameter" will show up as a local variable in here
}


http://www.cplusplus.com/doc/tutorial/functions/
Topic archived. No new replies allowed.