-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathBai66.cpp
More file actions
46 lines (36 loc) · 757 Bytes
/
Bai66.cpp
File metadata and controls
46 lines (36 loc) · 757 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
/*
Đọc ghi file trong C++
- $66: đọc file text
- $67: ghi file text
- $68: ghi file nhị phân
- $69: đọc file nhị phân
- $70: Bài tập tổng hợp đọc ghi file với object
*/
#include <iostream>
#include <fstream>
using namespace std;
void showInfo(int* a, size_t n) {
for (size_t i = 0; i < n; i++)
{
cout << a[i] << " ";
}
cout << "\nDONE";
}
int main() {
// mo file -> doc du lieu -> dong file
// fstream ifs("input.txt", ios::in); // c1
// ifs.open("C:/Users/ADMIN/Desktop/input.txt"); // c2
ifstream ifs2("input.txt");
// ifs2.open("input.txt");
size_t n;
int* arr;
ifs2 >> n;
arr = new int[n];
for (size_t i = 0; i < n; i++)
{
ifs2 >> arr[i];
}
showInfo(arr, n);
ifs2.close();
return 0;
}