Created
March 15, 2009 21:29
-
-
Save lukaskonarovsky/79542 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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