By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

cout, cerr and I/O redirection

P: n/a
Hello folks,

Novice type question here.

I'm working with a very simple app here that takes a series of strings
from the console. Once the end user has finished inputting the
strings they are individually processed and the result displayed back
to the console.

The problem I am having occurs during I/O redirection. Here is where
I am at the moment.

1) Run program with keyboard input and output redirected to file.
Never saw the prompt for the end user as it went straight to the
file. Fixed this, or so I thought, by having the end user prompt
displayed using cerr. Works like a charm, until we go to test
number 2.

2) Run program with both input and output being redirected. My user
prompt prints to the console before every line it accepts from the
input file. There are no problems with the output to the second
file from this operation. As my test suite consisted of ten
strings just to keep this simple one can see where, on large
files this behaviour would be annoying at the least but a big
performance hit no matter. I thought of using argc and argv but
when I/O redirection is in play it appears the argument count is
always 1 (program name) so is useless to me at this point.

My questions are:

Is the solution in problem 1 a reasonable approach to problem 1?

Given 1 works, how do I resolve the dilemma I now have at 2?
Thanks very much in advance.

Ken

Ken Wilson

Amer. Dlx. Tele, Gary Moore LP, LP DC Classic w/P90s,
Jeff Beck Strat, Morgan OM Acoustic,
Rick 360/12, Std. Strat (MIM), Mesa 100 Nomad,
Mesa F-30

"Goodnight Austin, Texas, wherever you are."
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Rick N. Backer" <ke********@NsOhSaPw.cAaM> schrieb im Newsbeitrag
news:l3********************************@4ax.com...
Hello folks,

Novice type question here.

I'm working with a very simple app here that takes a series of strings
from the console. Once the end user has finished inputting the
strings they are individually processed and the result displayed back
to the console.

The problem I am having occurs during I/O redirection. Here is where
I am at the moment.


I/O redirection is something your OS does to you. C++ does not know or care
about such features. But there might be some function in your compiler's
library telling you whether input and/or output have been redirected. I have
seen isatty or _isatty in several libraries, so that's what I would look
for, first.

HTH
Heinz
Jul 23 '05 #2

P: n/a


Heinz Ozwirk wrote:
"Rick N. Backer" <ke********@NsOhSaPw.cAaM> schrieb im Newsbeitrag
news:l3********************************@4ax.com...
Hello folks,

Novice type question here.

I'm working with a very simple app here that takes a series of strings
from the console. Once the end user has finished inputting the
strings they are individually processed and the result displayed back
to the console.

The problem I am having occurs during I/O redirection. Here is where
I am at the moment.
I/O redirection is something your OS does to you. C++ does not know or care
about such features. But there might be some function in your compiler's
library telling you whether input and/or output have been redirected. I have
seen isatty or _isatty in several libraries, so that's what I would look
for, first.


Thank you for this. It was indeed the other half of the answer that I
was missing.
HTH
Heinz


Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.