Created
October 10, 2018 08:53
-
-
Save frankyueh/aebc33a52b15782cd44d022da0304298 to your computer and use it in GitHub Desktop.
tail_cp
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 <fstream> | |
#include <iterator> | |
#include <algorithm> | |
#include <cstdlib> | |
int main(int argc, char *argv[]) | |
{ | |
std::ifstream in(argv[1], std::ios::ate); | |
std::ofstream out(argv[2]); | |
in.seekg(-std::min(static_cast<std::ios::pos_type>(std::atoi(argv[3])), in.tellg()), std::ios::end); | |
std::copy( | |
std::istreambuf_iterator<char>(in), | |
std::istreambuf_iterator<char>(), | |
std::ostreambuf_iterator<char>(out)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment