------------------------------------------------------------------------------
MC logo
Opening a file
[^] OS Concepts And Design
------------------------------------------------------------------------------
fileread1.cpp
#include <iostream>
#include <string>
using namespace std;

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

main(int argc, char **argv)
{
        int fd = open(argv[1], O_RDONLY);
        if(fd < 0)
                cerr << "File open failed." << endl;
        else {
                char buf[1024];
                int nchr;
                while((nchr = read(fd, buf, sizeof buf)) > 0)
                        cout.write(buf, nchr);
        }
}