#include #include #include #include using namespace std; using MyNumberT = short; int main(){ int flag1{O_WRONLY|O_CREAT|O_EXCL}; int flag2{ S_IRUSR | S_IWUSR |S_IRGRP | S_IROTH}; int fd{open("binaryFile", flag1, flag2)}; if (fd == -1) { perror("\tError open:"); cerr << "\tDid you remove binaryFile?" << endl; } cout << endl; cout << "FD = " << fd << endl; cout << "The size of an int is " << sizeof(int) << endl; cout << endl; for(MyNumberT i = 0; i < 10; ++i) { ssize_t size; size = write(fd, &i, sizeof(MyNumberT)); if (size < 0) { perror("\tError write:"); } cout << "wrote " << i << endl; } close(fd); return 0; }