Skip to content

Instantly share code, notes, and snippets.

@lukaskonarovsky
Created March 15, 2009 21:29
Show Gist options
  • Save lukaskonarovsky/79542 to your computer and use it in GitHub Desktop.
Save lukaskonarovsky/79542 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[]) {
vector<string> lines;
string line;
int keep_lines = 5;
int lines_in_buffer = 0;
if (argc == 2) {
keep_lines = atoi(argv[1]);
}
while (!getline(cin, line, '\n').eof()) {
lines_in_buffer++;
lines.insert(lines.begin(), line);
if (lines_in_buffer > keep_lines) {
lines.pop_back();
}
}
vector<string>::reverse_iterator rii;
for (rii = lines.rbegin(); rii != lines.rend(); ++rii) {
cout << *rii << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment