Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cout

54 views
Skip to first unread message

Rosario19

unread,
Sep 26, 2015, 3:13:47 AM9/26/15
to
there is difference in cout output from :

cout.width(10);
cout.precision(2);
cout<<123.123;

and

cout.precision(2);
cout.width(10);
cout<<123.123;
?

Barry Schwarz

unread,
Sep 26, 2015, 4:23:49 AM9/26/15
to
On Sat, 26 Sep 2015 09:13:28 +0200, Rosario19 <R...@invalid.invalid>
wrote:
Not on my system. Maybe you should provide the complete function, and
the output your system produces.

--
Remove del for email

Rosario19

unread,
Sep 26, 2015, 11:44:53 AM9/26/15
to
here i not find they write different output...
so all ok... ok too this output
even if for me "precision number" is number of the digit afther the
point "." in the right
and not the number of all digits as the C++ seems to say

#include <iostream.h>

int main(void)
{double b=23.123;
cout<<"1: "<<b<<"\n";
cout.precision(2);
cout.width(10);
cout<<b<<"\n";
cout.width(10);
cout.precision(2);
cout<<b<<"\n";
cout.precision(2);
cout<<b<<"\n";
return 0;
}

/*
the output:
1: 23.123
23
23
23

*/

red floyd

unread,
Sep 26, 2015, 12:44:53 PM9/26/15
to
On 9/26/2015 8:44 AM, Rosario19 wrote:
> On Sat, 26 Sep 2015 01:23:31 -0700, Barry Schwarz wrote:
>> On Sat, 26 Sep 2015 09:13:28 +0200, Rosario19 <R...@invalid.invalid>
>> wrote:
>>
>>> there is difference in cout output from :
>>>
>>> cout.width(10);
>>> cout.precision(2);
>>> cout<<123.123;
>>>
>>> and
>>>
>>> cout.precision(2);
>>> cout.width(10);
>>> cout<<123.123;
>>> ?
>>
>> Not on my system. Maybe you should provide the complete function, and
>> the output your system produces.
>
> here i not find they write different output...
> so all ok... ok too this output
> even if for me "precision number" is number of the digit afther the
> point "." in the right
> and not the number of all digits as the C++ seems to say
>
> #include <iostream.h>
[redacted]

Since <iostream.h> is not a standard header, nobody here can tell
you what the expected behavior is.

Why are you still using <iostream.h> instead of <iostream>
17 years after standardization?



Barry Schwarz

unread,
Sep 26, 2015, 1:50:19 PM9/26/15
to
On Sat, 26 Sep 2015 17:44:32 +0200, Rosario19 <R...@invalid.invalid>
wrote:

>here i not find they write different output...
>so all ok... ok too this output
>even if for me "precision number" is number of the digit afther the
>point "." in the right
>and not the number of all digits as the C++ seems to say

You can choose any meaning you like when you use "precision number" in
your prose. However, if you want people to understand your writing,
it would be nice if you chose the already accepted meaning of words.
In mathematics, precision is closely related to significant digits
which does not distinguish between digits before and after the decimal
point.

When you use the precision member function in your C++ code, your
chosen meaning is irrelevant. The result of calling the function is
defined by the standard, not by the whims of the programmer.

Since you second code sample has almost no relation to your first, are
we still discussing your incorrect assertion that the order of calling
the precision and width functions causes different output?

Rosario19

unread,
Sep 26, 2015, 2:48:26 PM9/26/15
to
no it is not in discussion, i remembered it wrong etc

what could be in discussion coul be: if i need to show the number + 2
digit afther the point... in C i have
printf("%.2f", (double)123.123); -> "123.12"

what in C++?

Rosario19

unread,
Sep 26, 2015, 2:50:12 PM9/26/15
to
i like the past time

Lőrinczy Zsigmond

unread,
Sep 27, 2015, 12:59:52 AM9/27/15
to
Off: never use these in multi-threaded context,
because you cannot be sure when thread-switch occures.

Rosario19

unread,
Sep 27, 2015, 1:10:22 AM9/27/15
to
On Sun, 27 Sep 2015 06:59:35 +0200, L?rinczy Zsigmond wrote:

>Off: never use these in multi-threaded context,
>because you cannot be sure when thread-switch occures.

yes... but one can use something for make the print operation as one
atomic one
something

atomic(&output);
operations output
....
atomicEnd(&output);

but pheraps one has to know if input/output
can make possible some dead lock...
i don't know too much this argument etc

red floyd

unread,
Sep 28, 2015, 1:05:45 AM9/28/15
to
Irrelevant. Since <iostream.h> is not standard, it can do whatever
the hell it wants, and nobody can tell you what it is supposed to do.

0 new messages