Print the last K lines of a file using C++

Write a method to print the last K lines of an input file using C++.

My initial thoughts:
Using the same idea from this article, we place two pointers to the file, the fast pointer and the slow pointer. The fast pointer is K lines ahead of the slow pointer. When the fast pointer reaches the EOF, we can start to print everything from the slow pointer, all the way to the end.

My initial codes:

#include <stdlib.h>
using namespace std;

int main(int argc, const char* args[]) {
	ifstream slowIn, fastIn;[1]);[1]);
	string str;
	int K = atoi(args[2]);
	if(fastIn.is_open()) {
		for(int i = 0; i < K; ++i) {
			getline(fastIn, str);
	if(slowIn.is_open()) {
		while(getline(fastIn, str)) {
			getline(slowIn, str);
	while(getline(slowIn, str)) {
		cout << str << endl;


string L[K];
int lines = 0;
while (file.good()) {
	getline(file, L[lines % K]); // read file line by line
// if less than K lines were read, print them all
int start, count;

if (lines < K) {
	start = 0;
	count = lines;
} else {
	start = lines % K;
	count = K;

for (int i = 0; i < count; ++i) {
	cout << L[(start + i) % K] << endl;