-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path151.cpp
More file actions
57 lines (49 loc) · 855 Bytes
/
151.cpp
File metadata and controls
57 lines (49 loc) · 855 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>
#include<iostream>
using namespace std;
class openFile
{
public:
int fd;
openFile(char name[])
{
fd=open(name,O_RDONLY);
if(fd==-1)
{
cout<<"Unable to open file"<<endl;
}
else
{
cout<<"File Opened Successfully"<<endl;
}
}
int Displaysize()
{
char Arr[10];
int ret=0;
int iCnt=0;
while((ret=read(fd,Arr,10))!=0)
{
iCnt=iCnt+ret;
}
return iCnt;
}
~openFile()
{
close(fd);
}
};
int main()
{
char str[20];
int iRet=0;
cout<<"Enter File name"<<endl;
cin>>str;
openFile obj(str);
iRet=obj.Displaysize();
cout<<"File Size is "<<iRet<<endl;
return 0;
}