Running interactive C++ program w/ cerr causes superfluous linebreaks - IBM AS400
This is a discussion on Running interactive C++ program w/ cerr causes superfluous linebreaks - IBM AS400 ; How can I stop this behavior?
A statement like this:
int n = 10;
cerr
Causes:
This is the
10
number of
times.
If I were to use a regular C fprint(stderr,...) it works out fine.
Also, cout if also ...
-
Running interactive C++ program w/ cerr causes superfluous linebreaks
How can I stop this behavior?
A statement like this:
int n = 10;
cerr << "This is the " << n << " number of " << " times." << endl;
Causes:
This is the
10
number of
times.
If I were to use a regular C fprint(stderr,...) it works out fine.
Also, cout if also good. No problems.
"This is the 10 number of times."
-
Re: Running interactive C++ program w/ cerr causes superfluouslinebreaks
On Sep 14, 11:52*am, "Mr. K.V.B.L." wrote:
> How can I stop this behavior?
>
> A statement like this:
>
> int n = 10;
> cerr << "This is the " << n << " number of " << " times." << endl;
>
> Causes:
>
> This is the
> 10
> number of
> times.
>
> If I were to use a regular C fprint(stderr,...) it works out fine.
> Also, cout if also good. *No problems.
>
> "This is the 10 number of times."
(passed on from someone else who I asked about this...)
The ios::unitbuf flag controls the buffering. By default, this flag
is set for the cerr stream and causes the output buffer to be flushed
after each write operation. The manipulator "nounitbuf" clears the
ios::unitbuf flag:
cerr << nounitbuf;
cerr << "This is the " << n << " number of " << " times." << endl;
results in:
This is the 10 number of times.
-
Re: Running interactive C++ program w/ cerr causes superfluouslinebreaks
On Sep 15, 12:31*pm, WDS wrote:
> On Sep 14, 11:52*am, "Mr. K.V.B.L." wrote:
>
>
>
> > How can I stop this behavior?
>
> > A statement like this:
>
> > int n = 10;
> > cerr << "This is the " << n << " number of " << " times." << endl;
>
> > Causes:
>
> > This is the
> > 10
> > number of
> > times.
>
> > If I were to use a regular C fprint(stderr,...) it works out fine.
> > Also, cout if also good. *No problems.
>
> > "This is the 10 number of times."
>
> (passed on from someone else who I asked about this...)
>
> The ios::unitbuf flag controls the buffering. *By default, this flag
> is set for the cerr stream and causes the output buffer to be flushed
> after each write operation. *The manipulator "nounitbuf" clears the
> ios::unitbuf flag:
>
> cerr << nounitbuf;
> cerr << "This is the " << n << " number of " << " times." << endl;
>
> results in:
> This is the 10 number of *times.
(and even more info from another someone else...)
....but if they are still using the older version of the C++ library,
the nounitbuf() function does not exist and the unsetf() function must
be used.
Here are a couple of additional examples that may be useful.
The code to turn off the flag is different depending upon which
version of the streams code is being used. If the code is using
, the following should work:
#include
int main (int argc, char *argv[])
{
int n = 10;
cerr.unsetf( ios::unitbuf );
cerr << "This is the " << n << " number of " << "times." << endl;
}
If the code is using , the following should work:
#include
int main (int argc, char *argv[])
{
int n = 10;
std::cerr.unsetf( std::ios_base::unitbuf );
std::cerr << "This is the " << n << " number of " << "times." <<
std::endl;
}
-
Re: Running interactive C++ program w/ cerr causes superfluouslinebreaks
On Sep 15, 1:50*pm, WDS wrote:
> On Sep 15, 12:31*pm, WDS wrote:
>
> ...but if they are still using the older version of the C++ library,
> the nounitbuf() function does not exist and the unsetf() function must
> be used.
>
> Here are a couple of additional examples that may be useful.
>
> The code to turn off the flag is different depending upon which
> version of the streams code is being used. *If the code is using
> , the following should work:
>
> #include
>
> int main (int argc, char *argv[])
> {
> * int n = 10;
>
> * cerr.unsetf( ios::unitbuf );
> * cerr << "This is the " << n << " number of " << "times." << endl;
>
> }
>
> If the code is using , the following should work:
>
> #include
>
> int main (int argc, char *argv[])
> {
> * int n = 10;
>
> * std::cerr.unsetf( std::ios_base::unitbuf );
> * std::cerr << "This is the " << n << " number of " << "times." <<
> std::endl;
>
> }
>
>
All of this is GOLD, thanks so much.
Kelly