-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_reader.cpp
More file actions
42 lines (34 loc) · 765 Bytes
/
file_reader.cpp
File metadata and controls
42 lines (34 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
int flags = O_RDONLY;
char buf[10];
size_t count;
ssize_t rd;
string p;
string filetoRead;
cout << "What is the file to read";
cin >> filetoRead;
int fd = open(filetoRead.c_str(),flags,mode); //Open the file
count = sizeof(buf);
rd = read(fd,buf,count);
if(rd == -1)
{
cout << "Error has a occured exiting program";
exit(1);
}
else
for(int i = 0; i < count; i++)
{
cout << (buf[i]);
}
close(rd);
}