1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
double auxiliary[] = {
0, 3.623e-07, 3.623e-07, 0.00219843, 0.016128,
0, 0, 0, 0, 0,
4.83066e-07, 0, 0, 0, 0,
6.03833e-08, 0, 0, 0, 0,
0.0901358, 0.00586247, 0.000367129, 2.85009e-05, 0,
0, 0, 0.0410373, 0.0117251, 8.81596e-06,
2.16776e-05, 0, 0, 0, 5.91756e-06 };
int i = 0;
for (auto a : auxiliary)
{
if (i > 0 && i% 5 == 0) cout << '\n';
++i;
cout << setw(15) << a;
}
{
ofstream stm("numbers.bin", ios::binary);
stm.write(reinterpret_cast<const char*>(&auxiliary), sizeof(auxiliary));
}
{
cout << "\n\nReading:\n";
ifstream stm("numbers.bin", ios::binary);
int i = 0;
for (double read; stm.read(reinterpret_cast<char*>(&read), sizeof(read)); )
{
if ( auxiliary[i] != read) cout << "different\n";
if (i > 0 && i% 5 == 0) cout << '\n';
++i;
cout << setw(15) << read;
}
}
}
|