-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path152.cpp
More file actions
55 lines (50 loc) · 898 Bytes
/
152.cpp
File metadata and controls
55 lines (50 loc) · 898 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
#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_WRONLY|O_APPEND);
if(fd==-1)
{
cout<<"Unable to open file"<<endl;
}
else
{
cout<<"File Opened Successfully"<<endl;
}
}
void WriteData(char text[])
{
int iCnt=0;
char *start=text;
while(* text!=0)
{
iCnt++;
text++;
}
write(fd,start,iCnt);
}
~openFile()
{
close(fd);
}
};
int main()
{
char str[20],str2[30];;
int iRet=0;
cout<<"Enter File name"<<endl;
cin>>str;
cout<<"Enter what you want to insert"<<endl;
cin>>str2;
openFile obj(str);
obj.WriteData(str2);
return 0;
}