473,395 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

cout, cerr and I/O redirection

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
2 4674
"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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Dennis Lubert | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi people, I want to create my own variant of a cout Object, so that I can use different of those for debugging... Like this class, but as a...
2
by: Trevor | last post by:
Hello, Please bear with me, I am trying to learn C++. I am implementing some error/debug functions which format a message and output it to a C++ stream. I would like to design it using one low...
6
by: Omid | last post by:
Hi. I have problems when I try to redirect everything that is sent to cout to a file. I have one piece of code that works and one that does not work. The only difference is which headers I use....
3
by: George B | last post by:
When I redirect standard output, I would like to duplicate a few lines of this output to the console. If I add duplicates of the desired source statements, changing cout to cerr, it works fine,...
4
by: blackswift | last post by:
Hello,all I hava a problem that when did cout call its destructor? I used GCC compiler under linux , It compiles OK. and gives me : cons des as I haved expected.
5
by: Cliff Martin | last post by:
Hi, I am writing a simple filter type program that can take input from file or stdin, and output to a file or stdout. It would make life much easier if I could assign cin to a ifstream object...
9
by: realrobby | last post by:
Is this possible using ANSI libraries? If I have an exe that calls a black box DLL, and the DLL writes to the console, how can I get my exe to grab what the DLL wrote, modify it, and spit out a...
2
by: pompom | last post by:
hello all! i have to make a project for school , making a newsserver and a client. the thing is, i send messages between them to let the user know if everything is running ok. just some simple...
11
by: Adrian | last post by:
Is it possible to save a copy of cout the same way you can save a copy of stdout in C (I know C version is portable, but unix portable is good enough for me). I have to use a library which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.