-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecords.cpp
More file actions
49 lines (41 loc) · 878 Bytes
/
records.cpp
File metadata and controls
49 lines (41 loc) · 878 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
//기록
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//파일 쓰기
void write(string record) {
ofstream ofs("scores.txt", ios::app);
if (!ofs) { //파일 생성 실패시 예외처리
cerr << "!!!!에러: 파일을 만들지 못했습니다!!!!!" << endl;
return;
}
//커서 지정
ofs.seekp(0);
//파일에 기록 쓰기
ofs << record;
//파일쓰기닫기
ofs.close();
cout << " 기록쓰기를 완료했습니다!\n\n" << endl;
return;
}
//파일 읽기
void read() {
ifstream ifs("scores.txt");
if (!ifs) { //파일 읽기 실패시 예외처리
cout << "!!!!에러: 파일을 읽지 못했습니다!!!!!" << endl;
return;
}
std::cout << " [성적기록] " << endl;
//파일 내용 읽어서 출력
string record;
int i = 0;
while (!ifs.eof()) { //*중요: 공백인 경우 eof에 해당안됨
getline(ifs, record);
cout << record << endl;
}
//파일읽기닫기
ifs.close();
cout << "\n\n" << endl;
return;
}