-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10b Files
53 lines (34 loc) · 1.52 KB
/
10b Files
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
/*****************************
NOTE:
Before executing this code, make sure you change the working folder to the desktop otherwise the file won't be created.
To work with files, the working directory should be the same as that where the file is being created and the executable
./a.out will be run.
else you will have to specify the entire path of file in the filename which is a hectic task.
So make sure you do this.
Open terminal and use the following commands:
Mac/Linux users: cd Desktop
Windows users: I hate you ! :P
********************************/
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char info1[200] = "Game of Thrones is my favourite show and tyrion is my favourite character. He's still going strong "; // 26+9 bits
char info2[200] = "It is written by George R.R. Martin. He likes killing the favourites.";
char input[200];
ofstream ofile("Myfile.dat") ; //creating a new file if it doesn't exist
ofile.write(info1,30);
cout<<"Cursor is at position "<<ofile.tellp()<<endl;
ofile.seekp(15,ios::beg); // MOVE 15 BYTES from the beginning
cout<<"Cursor is at position "<<ofile.tellp()<<endl;
ofile.write(info2,20); // Write 20 bytes of info again
cout<<"Cursor is at position "<<ofile.tellp()<<endl;
ifstream ifile("Myfile.dat");
ifile.getline(input,sizeof(ofile.tellp()));
cout<<"****************************************"<<endl;
cout<<input<<endl;
cout<<"****************************************"<<endl;
cout<<"END OF FILE REACHED. Ending Program"<<endl;
return 0;
}