You are continuing on topic that you have started in
http://www.cplusplus.com/forum/unices/159802/
and
http://www.cplusplus.com/forum/general/161313/
You should not ask how "wc" woks. You should ask how every program writes to standard output.
You should ask what it means to "pipe", aka to redirect the standard output into the standard input of an another program.
When you use that command line
from the point of view of the
prog it is exactly same as you would use
and personally type the following as input:
1 1 6 file1.txt
1 1 1 file2.txt
2 2 7 total |
You are writing the
prog, so your program must read std::cin appropriately.
Every line (of wc output) contains three integers and a filename (or word "total"). Filenames unfortunately can contain whitespace. The integers can be read as formatted input, and formatted input does by default skip the leading whitespace. A getline can read the filename/word.
Forget the wc and concetrate on reading input.