Put another way: READ THE BOOK! I know it's not the most gripping reading that you'll have this year, but wade your way through it -- it's good information.
UNIX> a.out Hello World! UNIX> a.out > f.txt UNIX> cat f.txt Hello World! UNIX> cat < f.txt Hello World! UNIX>You'll see that the second statement has "standard output redirected to the file f.txt".
Note, if you don't give the program cat any arguments, it will read from standard input. So the second cat statement above takes "redirects standard input from f.txt."
Finally, the vertical bar is called a "pipe". It is used to separate two commands, and to have standard output of the command to the left of the pipe go into standard input of the command to the right. For example:
UNIX> a.out Hello World! UNIX> a.out | cat -n 1 Hello World UNIX> a.out | cat -n | cat -n 1 1 Hello World UNIX> a.out | cat -n | cat -n | cat -n 1 1 1 Hello World UNIX>
UNIX> lynx -dump http://www.nba.com/games/20070117/scoreboard.html > nba.txtthen vi nba.txt and use slash to search for Knicks. Oh, they lost. Pity.
// hw.cpp // Program to print out hello world. // Jim Plank #include < iostream > using namespace std; int main() { cout << "Hello World\n"; return 0; } |
Note, this differs from the book's first program in that I include the "using namespace std" line. This allows me to specify that I'm writing to cout rather than std::cout. Also note that I didn't go crazy with fifty comments like the book does. I'm an advocate for clean, clear, and sparse comments.