#include "pch.h" #include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <ctime> #include <fstream> #include <iomanip> using namespace std; inline void eatline() { while (cin.get() != ' ') continue; } struct planet { char name[20]; double population; double g; }; const char* file = "planets.dat"; int main(void) { planet pl; cout << fixed; ifstream fin; fin.open(file,ios_base::in|ios_base::binary); if (fin.is_open()) { cout << "Here are the current contents of the " << file << " file: "; while (fin.read((char*) &pl,sizeof pl)) { cout << setw(20) << pl.name << ": " << setprecision(0) << setw(12) << pl.population << setprecision(2) << setw(6) << pl.g << endl; } fin.close(); } ofstream fout(file, ios::out | ios::app | ios::binary); if (!fout.is_open()) { cerr << "Can't open " << file << " file for output. "; exit(EXIT_FAILURE); } cout << "Enter guest names (enter a blank line to quit): "; cin.get(pl.name, 20); while (pl.name[0]!='