First off, the semicolon after the if
-statement is the complete conditional block of the if
-statement (and it absolutely can go on the previous line but almost certainly you don't want to have the semicolon in the first place). In addition, you always need to check your input after reading! The stream has no idea what you are going to attempt next and can't predict whether it will be successful before actually trying. That is, your code should look something like this:
std::ifstream in(argv[1]);
if (!in) {
std::cout << "ERROR: failed to open '" << argv[1] << "' for reading\n";
}
else {
int i, j, k;
if (std::cin >> i >> j >> k) {
std::cout << "read i=" << i << " j=" << j << " k=" << k << '\n';
}
else {
std::cout << "ERROR: there was a format error\n";
}
}
That said, based on your code you should see the expected output assuming you, indeed, managed to correctly open the file. I'd guess that the code above will point out what's going wrong.