Remove x number of lines from beginning of file

Steve smorrey at
Thu Oct 25 17:52:19 MDT 2007

Most MMO's use UDP :)  And yes I am still writing an online book about it.
I've been working on getting my code tightened down as much as
possible, progress is slow and steady, but at least it's progress.  I
think I'll add the UDP based bittorrent replacement to the book.  If
nothing else it would make a good distribution medium for updates.

Anyways back to the subject, I whipped up a little program that should
do the trick.
Compile it and see if the results are a little better.  I can't vouch
that it does anything other than compile correctly, but it looks
mostly correct.

#include <iostream>
#include <fstream>

int main(int argc, char* argv[]){
	if(argc > 2){
		std::string filename = argv[1];
		int skiplines = atoi(argv[2]);
		std::string action = "mv temp.out ";
		std::ifstream infile (filename.c_str());
		std::ofstream outfile ("temp.out");
		std::string line;
		int x = 1;
		if(infile.is_open() && outfile.is_open()){
				if(x < skiplines){ outfile << line;}else{ x++;}
		        action += filename;
		std::cout << "frontcate is a program intended to truncate a given
number of lines from the front of a file" << std::endl;
		std::cout << "Usage: truncate FILENAME LINES" << std::endl;

On 10/25/07, Levi Pearson <levi at> wrote:
> Shane Hathaway <shane at> writes:
> > Steve wrote:
> >> What about using nice and running it at a higher priority?
> >
> [... snip ...]
> > [OT] Hey, I thought you were busy writing a new peer-to-peer UDP
> > protocol. :-)
> I thought he was busy writing an online book about how to program a
> MMO game using UDP. :P
> I guess he's nice'd those processes, though. ;)
>                 --Levi
> /*
> PLUG:, #utah on
> Unsubscribe:
> Don't fear the penguin.
> */

More information about the PLUG mailing list