#include // so I can do reasonable i/o #include // open at least #include // open #include // open #include // read #include // strcmp #include // perror const int BUFFER_SIZE = 1024; using namespace std; void Usage(char *); int main(int argc, char * argv[]) { int inputFD, outputFD, openFlags; ssize_t numRead; char buf[BUFFER_SIZE]; // open the input file. inputFD = open("datafile.dat", O_RDONLY); if (inputFD == -1) { perror("Could not open the inputfile "); return 1; } // remember the output file contains an int, a float, a char and a string. int a; float b; char c; string d; numRead = read(inputFD, &a, sizeof(int)); cout << "The integer is " << a << endl; numRead = read(inputFD, &b, sizeof(float)); cout << "The float is " << b << endl; numRead = read(inputFD, &c, sizeof(char)); cout << "The char is " << c << endl; // I have a couple of choices here, I could just read to the end of the file // I will read until I get to the null. while((numRead = read(inputFD, &c, sizeof(char)) != 0) and (c != '\0') ) { d += c; } cout << "The string is \"" << d << "\"" << endl; if (numRead == -1) { perror("A read failed"); return 1; } if(close(inputFD) == -1) { perror("Fail on closing input file"); return 1; } return 0; } void Usage(char * name) { cout << "Usage: " << name << " inputFile outputFile " << endl; return; }