Try ios:in
std::ifstream in( argv[1],ios::in | ios::binary)
Or, in fact
std::ifstream in( argv[1],ios::binary)
Which is equivalent:
First, performs the same steps as the default constructor, then asssociates the stream with a file by calling
rdbuf()->open(filename, mode | std::ios_base::in)
.. If the open() call returns a null pointer, sets setstate(failbit)
Here's my (untested) simplist take on it:
#include <fstream>
int main(int /*argc*/, const char *argv[])
{
std::ifstream in(argv[1], std::ios::binary);
if (in)
{
std::ofstream myfile("selfoutput", std::ios::binary);
if (myfile)
myfile << in.rdbuf();
}
}
In the interest of gratuitous code golf and bad style:
#include <fstream>
using namespace std;
int main(int /*argc*/, const char *argv[]) {
ofstream("selfoutput", ios::binary) << ifstream(argv[1], ios::binary).rdbuf();
}