Created
March 18, 2013 12:36
-
-
Save Battleroid/5186884 to your computer and use it in GitHub Desktop.
Creates binary file filled with random integers, appends information if file already exists.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iostream> | |
#include <ctime> | |
#include <random> | |
using namespace std; | |
int main () { | |
// create random array | |
int array[100]; | |
srand(time(0)); | |
for (int i = 0; i < 100; i++) { | |
int tmp = rand() % 10 + 1; | |
// cout << i << " = " << tmp << endl; | |
array[i] = tmp; // 1-10 | |
} | |
// open and append | |
fstream output("Exercise13_13.dat", ios::app | ios::out | ios::binary); | |
if (output.is_open()) { | |
output.write((char *) &array, sizeof(array)); | |
output.close(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment