-
Notifications
You must be signed in to change notification settings - Fork 0
/
filehandling.cpp
66 lines (57 loc) · 942 Bytes
/
filehandling.cpp
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
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct stud{
int roll;
int marks;
string name;
};
stud s;
main()
{
x:
int c;
cout<<"Enter choise\n1->add rec\n2->display rec\n";
cin>>c;
if (c==1)
{
cout<<"Enter Roll no ";
cin>>s.roll;
cout<<"Enter Marks ";
cin>>s.marks;
cin.ignore();
cout<<"Enter name";
getline(cin,s.name);
ofstream file("data.txt",ios::app);
file<<s.roll<<"\n";
file<<s.marks<<"\n";
file<<s.name<<"\n\n";
file.close();
}
else if(c==2)
{
ifstream read;
read.open("data.txt");
string roll,marks,name,space;
while(read)
{
if(read.eof())
{
break;
read.close();
}
else
{
getline(read,roll);
getline(read,marks);
getline(read,name);
getline(read,space);
cout<<"Name : "<<name<<endl;
cout<<"marks : "<<marks<<endl;
cout<<"roll : "<<roll<<endl;
}
}
}
goto x;
}