writing a strcutures to a file
here is my current code
it writes some variables from the record struct to a file
but i trying to find a way to write just the entire struct to the file, after the user has entered in his detials, the file dosetn have to be readable by human, just by machine
#include <iostream>
#include <fstream>
#include <stdlib.h>
//using namespace std;
using namespace std;
using std::cout;
using std::cin;
int main()
{
struct record
{
char fname[15];
char lname[20];
int cage;
char acctype[1];
int nbalance;
};
struct record rec;
cout << "you will need to enter in some information, below is a table, fill it out to proceed\n";
cout << "first name: ";
cin >> rec.fname;
cout << "\nlast name: ";
cin >> rec.lname;
cout << "\nyour age: ";
cin >> rec.cage;
cout << "\nnow we need to know your account type\n";
cout << "enter s for savings, c for cheque, i for investment: ";
cin >> rec.acctype;
cout << "\nSet your initial balance: ";
cin >> rec.nbalance;
ofstream SaveFile("record.txt");
SaveFile << "firstname: " << rec.fname;
SaveFile << " secound name: " << rec.lname;
SaveFile << " age: " << rec.cage;
SaveFile << " account type: " << rec.acctype;
SaveFile << " initial balance: " << rec.nbalance;
SaveFile.close();
|