Is there an efficient way to toss binary data in C++?
Below if the code I'm using. I wonder if anyone knows a faster way to do what I'm doing, which is taking in a file (piping it from a bash terminal like "./a.out < input > output") by reading its data byte by byte, and throwing out every other byte (so the final output is 1/2 the original).
I find that that way I'm doing it is really slow (it takes about a second to process 1.2 Mbytes). Is there a way to do this faster? I think that reading the file in at once might speed things up so that cin doesn't have to be called over and over, but I don't know how to go about doing that.
Code:
#include<iostream>
using namespace std;
main()
{int i=0;
char ch;
while(cin.get(ch))
{if(i == 1)
{cout << ch;
i = 0;
}
else if(i == 0)
{i = 1;
}
else {exit(-1);}
}
}