Firstly, a struct is almost the same as class. The only difference is that evrything is public by default. For a class the default is private
Secondly what you are trying do do with the cast is wrong. The compiler will let you cast anything to anything. You cannot cast your struct to a char*.
Theres a few ways to do what you want. I will illustrate a couple of simple solutions with the write part of your example.
1) Write each member of the struct individually using the << in the filestream, so
cin>>Acc.balance;
cin>>Acc.Owner;
File.open("Account.txt",ios::out|ios::trunc);
//write the balance and add space
File<<Acc.balance<<" ";
//write the owner, this wil cal strings << operator
File<<Acc.Owner;
File.close();
2) Create << operator in the struct, so your struct will be
struct Account{
float balance;
string Owner;
friend fstream& operator<<(fstream& f, Account& acc)
{
f<<acc.balance<<" "<<acc.Owner;
return f;
}
};
then in the write bit
cin>>Acc.balance;
cin>>Acc.Owner;
File.open("Account.txt",ios::out|ios::trunc);
//write the struct contents
File<<Acc;
File.close();
You can do something similar for the read.