+ 1

Binary file

Write a structure ,City ,for a record that contains a city name of 20 characters and its population.  The structure is used for a binary file processing.

29th Oct 2016, 12:00 AM
Shannon Hostetler
Shannon Hostetler - avatar
1 Odpowiedź
0
in C++ _______ #include<iostream.h> #include<fstream.h> //for handling files in cpp #include<stdlib.h> // structure goes here struct City{ char city_name[20]; float population; }; //main programs void main() { ofstream fout; // open file in output mode and binary fout("file.dat",ios::out | ios::binary); City c1; //execute the below lines in a loop to get more input gets(c1.city_name); // gets string input from user cin>>c1.population; // gets population from user fout.write((char*)&c1,sizeof(c1)); }
4th Nov 2016, 3:27 PM
Paul P Joby
Paul P Joby - avatar