Advertisement
rihardmarius

final 1b - crear archivo

Nov 24th, 2013
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include "libreria archivos.cpp"
  2.  
  3. using namespace std;
  4.  
  5. struct par {
  6.     int cantidad = 0;
  7.     double promedio = 0;
  8. };
  9.  
  10. struct file_t {
  11.     int segundo = 0;
  12.     int latitud = 0;
  13.     int longitud = 0;
  14.     double temperatura = 0;
  15. };
  16.  
  17. void mostrar_record (file_t& rec)
  18. {
  19.     cout << rec.segundo << ' ' << rec.latitud << ' ' << rec.longitud << ' ' << rec.temperatura << endl;
  20. }
  21.  
  22. int main()
  23. {
  24.     file_t record;
  25.     ofstream output ("medidas.bin", ios::binary);
  26.     array<file_t,100> arr;
  27.  
  28.     check_open(output);
  29.  
  30.     for(int i = 0; i<100; i++) // setea array
  31.     {
  32.         //arr.at(i).segundo = i+48;
  33.         arr.at(i).latitud = i-50;
  34.         arr.at(i).longitud = i;
  35.         arr.at(i).temperatura = i-60;
  36.     }
  37.  
  38.     for(int i = 0; i<100; i++) // muestra array
  39.         cout << arr.at(i).segundo << ' ' << arr.at(i).latitud << ' ' << arr.at(i).longitud << ' ' << arr.at(i).temperatura << endl;
  40.     cout << endl;
  41.  
  42.     for (int i=0; i<100; i++) // escribe archivo
  43.         writeblock(output,arr.at(i));
  44.  
  45.     close_file(output);
  46.  
  47.     ifstream input ("medidas.bin", ios::binary); // lee archivo
  48.  
  49.     check_open(input);
  50.  
  51.     while(readblock(input,record))
  52.     {
  53.         mostrar_record(record);
  54.     }
  55.     cout << endl;
  56.  
  57.     mostrar_estado(input);
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement