This is an old revision of the document!
I/O Redirection (<>)
I/O redirection is part of most shell systems. This process allows the user to enter data into a program from a file instead of the keyboard, or send the output of a program to a file instead of the screen.
An Example
An example might be a good place to start. Assume the following code is in hello.cpp
#include <iostream> using namespace std; int main() { string name; cout << "Enter your name : "; getline(cin, name); cout << endl; cout << "Hello " << name << "!" << endl; return 0; }
When this code is compiled and run, the output will be something like this
$ hello Enter your name : Dan Hello Dan!
In this example the input is read from the keyboard and the output is written to the screen.
But let's assume that you want to test your program for Queen Elizabeth when she is in Scotland. Her official style is Elizabeth the Second, by the Grace of God of the United Kingdom of Great Britain and Northern Ireland and of Her other Realms and Territories Queen, Head of the Commonwealth, Defender of the Faith , which is just a little too much to type every time you wish to test your program.
A solution is to place this information in a file. So create the file queenName that contains this information.
$ cat queenName Elizabeth the Second, by the Grace of God of the United Kingdom of Great Britain and Northern Ireland and of Her other Realms and Territories Queen, Head of the Commonwealth, Defender of the Faith