Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdio>
- #include "time.h"
- using namespace std;
- int main(){
- srand((unsigned)time(NULL));
- fstream file("in.bin", ios::out | ios::binary), out("out.bin", ios::out | ios::binary);
- if (!file.is_open()){
- cout << "[FILE] Error reading file" << endl;
- return 0;
- } else {
- cout << "[FILE] File successfuly opened" << endl;
- }
- for (int i = 0; i<1010; i++){
- double data = (rand()%1000010*100.0)/10000;
- file.write(reinterpret_cast<char*> (&data), sizeof(double));
- }
- file.close();
- file.open("in.bin", ios::in | ios::binary);
- double* array = new double[1011];
- int size = 0;
- while (!file.eof()){
- double data;
- file.read(reinterpret_cast<char*> (&data), sizeof(double));
- array[size++] = data;
- }
- double ans = -INT_MAX;
- for (int i = 0; i<size; i++){
- if (i % 9 == 0 && i != 0){
- cout << "[LOG] Wrote maximum from previous 10 elements: " << ans * 1.0 << endl;
- out.write(reinterpret_cast<char*> (&ans), sizeof(double));
- ans = -INT_MAX;
- }
- ans = max(ans, array[i]);
- }
- out.close();
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment