#include #include #include #include using namespace std; using MyNumberT = int; 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)}; //int fd; //if ((fd = open(...)) == -1) { if (fd == -1) { cerr << "The error number was " << errno << endl; perror("\tError open:"); cerr << "\tDid you remove binaryFile?" << endl; return 1; } 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 << " in " << sizeof(i) << " bytes." << endl; } string hello{"Hello World"}; write(fd, hello.c_str(), sizeof(char)*hello.size()); close(fd); return 0; }