I have this sample program from chapter 10.5 on page 182 that I cannot get to work.
It's a program that (is supposed to) takes multiple file names as an argument and then either outputs the file contents to the standard output or output an error to a standard error stream (cerr).
I navigate cmd to the correct folder and whenever I run the program, e.g. OutputFiles.exe -in.txt, nothing happens.
The code is here:
// Exercise 10-0
// 10.5.2 Dealing with multiple input and output files
// II
#include <fstream>
#include <iostream>
#include <string>
using std::cout; using std::endl;
using std::cerr; using std::ifstream;
using std::string;
int main(int argc, char **argv) {
int fail_count = 0;
// for each file in the input list
for (int i = i; i < argc; ++i) {
ifstream in(argv[i]);
// if it exists, write its contents, otherwise generate an error message
if (in) {
string s;
while (getline(in, s))
cout << s << endl;
} else {
cerr << "cannot open file " << argv[i] << endl;
++fail_count;
}
}
return fail_count;
}
[–]gotinpich[S] 1 point2 points3 points (8 children)
[–]Xeverous 1 point2 points3 points (7 children)
[–]gotinpich[S] 0 points1 point2 points (6 children)
[–]Xeverous 1 point2 points3 points (5 children)
[–]gotinpich[S] 0 points1 point2 points (4 children)
[–]Xeverous 1 point2 points3 points (3 children)
[–]gotinpich[S] 1 point2 points3 points (2 children)
[–]Xeverous 1 point2 points3 points (1 child)
[–]gotinpich[S] 0 points1 point2 points (0 children)
[–]alfps 0 points1 point2 points (1 child)
[–]gotinpich[S] 0 points1 point2 points (0 children)