-
Notifications
You must be signed in to change notification settings - Fork 0
/
13_1.cpp
49 lines (42 loc) · 896 Bytes
/
13_1.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
//
// 13_1.cpp
//
//
// Created by Pengyan Qin on 7/17/15.
//
//
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
void printLastKLines(int k, string filename){
fstream fin;
fin.open(filename.c_str());
if(!fin.is_open()){
cout << "fail to open" << endl;
exit(1);
}
arr[k]; // string array can define without initialization
int l_num = 0;
string line;
int ind = 0;
while(getline(fin, line)){
l_num++;
if(ind >= k)
ind = ind % k;
arr[ind] = line;
}
int start = l_num % k;
for(int i = start; i < k; ++i)
cout << *(sptr + i) << endl;
if(start != 0){
for(int i = 0; i < start; ++i)
cout << << endl;
}
}
int main(){
string filename = "13_1.in";
int k = 4;
printLastKLines(k, filename);
}