rendered paste body#include <sys/types.h>
#include <fcntl.h>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int fd;
size_t size;
char string[] = "Hello, world!\n";
umask(0);
if (fd = open("somefile", O_WRONLY | O_CREAT, 0666) < 0)
{
cout << "A terrible error occured\n";
exit(-1);
}
cout << fd << endl;
size = write(fd, string, 14);
if (size != 14)
{
cout << "can't write all the string\n";
exit(-1);
}
if (close(fd) < 0)
cout << "can't close the file\n";
return EXIT_SUCCESS;
}