WhatMeWorry
2006.06.18, 08:48 PM
This is probably so simple or basic that all my books and web searches have turned up nothing..but
Can the cin be redirected from the keyboard to some arbitrary data file?
I've got code which uses <istream> and cin, but has data files. To me
as soon as I see data files, I think <ifstream>. And as soon as I see <istream>
I think of typing data at the terminal and entering return.
But the code (not my own) I'm studying has the following:
int main()
{
// read and store the data
while (cin >> ch) {
if (ch == 'U')
record = new Core; // allocate a `Core' object
else
record = new Grad; // allocate a `Grad' object
but a data file like:
G Moo 100 100 100 100 100 100 100 100 100
U Moore 75 85 77 59 0 85 75 89
G Norman 57 78 73 66 78 70 88 89 84
So seems to me, their must be a way to seat cin to the data file and NOT the keyboard.
Can the cin be redirected from the keyboard to some arbitrary data file?
I've got code which uses <istream> and cin, but has data files. To me
as soon as I see data files, I think <ifstream>. And as soon as I see <istream>
I think of typing data at the terminal and entering return.
But the code (not my own) I'm studying has the following:
int main()
{
// read and store the data
while (cin >> ch) {
if (ch == 'U')
record = new Core; // allocate a `Core' object
else
record = new Grad; // allocate a `Grad' object
but a data file like:
G Moo 100 100 100 100 100 100 100 100 100
U Moore 75 85 77 59 0 85 75 89
G Norman 57 78 73 66 78 70 88 89 84
So seems to me, their must be a way to seat cin to the data file and NOT the keyboard.