you will need to include either fstream.h (or fstream depending on your compiler) in order to use an ofstream (which is usually what fout is) in your program.
The first error says the compiler can't use fout because it hasn't been declared as a valid object.
The second error says you haven't successfully overloaded the << operator for the class you are using. It may "magically" go away if you correct the first problem.
Code:
#include <fstream.h>
const int MAX = 10;
class sample
{
public:
int data;
char name[MAX];
//overload the << operator for the class sample using friend
friend ostream & ostream<<(ostream & os, sample & s);
};
//definition of overloaded << operator for class sample
ostream & ostream<< (ostream & os, sample & s)
{
os << s.data << endl << s.name << endl;
return os;
}
int main()
{
sample sample1;
sample1.data = 1;
strcpy(sample1.name, "Spot");
ofstream fout("myFile.txt");
fout << sample1;
return 0;
}
disclaimer: code untested.