#include // so I don't have to do lo level io everywhere. #include // close, and in general #include //read #include //read #include //read #include // perror #include using namespace std; const char * filename = "scratch"; int main() { int fd; int x = 7; char buf[4]; int num = -1; // more on this open soon. fd = open(filename, O_WRONLY | O_CREAT , S_IRWXU | S_IRGRP | S_IROTH ); if (-1 == fd) { perror("Open failed"); return -1; } // write the four bytes of the string. write(fd,"1234",4); // write the data stored at x, all of it. write(fd, &x,sizeof(int)); // show the difference between writing an int and the string. x = INT_MAX; write(fd, &x,sizeof(int)); write (fd, "2147483647",10); // an experiment for byte order. x = 0x01020304; write(fd, &x,sizeof(int)); close(fd); // now read everything back in. fd = open(filename, O_RDONLY); read(fd, buf, 4); read (fd, &num, sizeof(int)); cout << "The buffer is " << buf << " and the int is " << num << endl; close(fd); return 0; }