-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLAB10.cpp
More file actions
30 lines (30 loc) · 767 Bytes
/
Copy pathLAB10.cpp
File metadata and controls
30 lines (30 loc) · 767 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
/*Develop a C++ program to write and read time in/from binary file using fstream*/
#include <fstream>
#include <iostream>
#include<stdlib.h>
using namespace std;
int main()
{
fstream fh;
int h,m,s;
fh.open("File_1.txt", ios::out|ios::binary);
if(!fh.is_open())
{
cout << "File did not open!";
exit(1);
}
cout<<"Enter time in hh mm ss format\n";
cin>>h>>m>>s;
fh.write((char *)&h,sizeof(int));
fh.write((char *)&m,sizeof(int));
fh.write((char *)&s,sizeof(int));
fh.close();
fh.open("File_1.txt",ios::in);
int h1,m1,s1;
fh.read((char *)&h1,sizeof(int));
fh.read((char *)&m1,sizeof(int));
fh.read((char *)&s1,sizeof(int));
cout<<h1<<":"<<m1<<":"<<s1;
fh.close();
return 0;
}