#include <iostream>
#include <vector>
using std::cout;
using std::vector;
using std::string;
class File {
private:
FILE * fp;
char * line = NULL;
size_t len = 0;
ssize_t read;
string str;
vector<string> stvec;
bool ReadLine();
public:
File(FILE * fptr) {
fp = fptr;
}
void printLines(size_t LineCount);
};
bool File::ReadLine() {
if(fp == NULL ){
return false;
}
while((read = getline(&line, &len, fp)) != -1) {
str = line;
stvec.push_back(str);
}
fclose(fp);
if(line) {
free(line);
}
return true;
}
void File::printLines(size_t LineCount) {
if(ReadLine()){
if(LineCount <= 0) {
exit(EXIT_FAILURE);
}
if(stvec.end() <= stvec.begin() + LineCount) {
for(vector<string>::iterator i = stvec.begin(); i < stvec.end(); i++) {
cout << * i << std::endl;
}
}
if(stvec.end() > stvec.begin() + LineCount && LineCount > 0) {
for(vector<string>::iterator i = stvec.begin(); i < (stvec.begin() + LineCount); i++) {
cout << * i << std::endl;
}
}
}
}
int main(int argc, char *argv[]) {
FILE * fp = fopen("text.txt", "r");
File F(fp);
F.printLines(1);
return 0;
}