Hey guys,
Below code isn't working as I expect it to do. I expect it to read all params when 6 are given, buuuuuuuuuuuut it only reads one, the rest remains zero. It does enter the case, but the stringstream buf seems empty. What am I doing wrong?
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
#define SCREAM cout << "OMAGAWD" << endl
int main(int argc, char *argv[])
{
// <src> <dest> [<offset> [<bytes, 0 = all> [<offset>]]
//writes bytes bytes from src+offset to dest+offset
size_t in_offset;
size_t bytes;
size_t out_offset;
in_offset = bytes = out_offset = 0;
stringstream buf;
switch (argc)
{
case 6:
SCREAM;
buf.str(argv[5]);
buf >> out_offset;
case 5:
SCREAM;
buf.str(argv[4]);
buf >> bytes;
case 4:
SCREAM;
buf.str(argv[3]);
buf >> in_offset;
default:
ifstream in(argv[1], ios::binary);
ofstream out(argv[2], ios::binary);
break;
}
cout << "Writing from " << argv[1] << " + " << in_offset << " to " << argv[2] << " + " << out_offset << " for " << bytes << " bytes" << endl;
return 0;
}
Example params: program.exe aap noot 1 2 3
example output:
OMAGAWD
OMAGAWD
OMAGAWD
Writing from aap + 0 to noot + 3 for 0 bytes
Thanks in advance,