Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #5934 > unrolled thread
| Started by | Ruben Safir <ruben@mrbrklyn.com> |
|---|---|
| First post | 2011-06-01 01:45 +0000 |
| Last post | 2011-06-03 02:56 -0700 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.c++
basic_ostream question Ruben Safir <ruben@mrbrklyn.com> - 2011-06-01 01:45 +0000
Re: basic_ostream question red floyd <no.spam.here@its.invalid> - 2011-05-31 21:50 -0700
Re: basic_ostream question ruben safir <ruben@mrbrklyn.com> - 2011-06-02 22:44 -0400
Re: basic_ostream question Michael Doubez <michael.doubez@free.fr> - 2011-06-03 02:56 -0700
| From | Ruben Safir <ruben@mrbrklyn.com> |
|---|---|
| Date | 2011-06-01 01:45 +0000 |
| Subject | basic_ostream question |
| Message-ID | <is45j3$s8u$1@reader1.panix.com> |
can simeone explain why the last 3 lines don't behave like expected
#include <iomanip>
int main(int argv, char ** argc){
char x = 'm';
float a = 3.14, b = 9.3453, e = 3, f = 1/3;
f = (1.0 / 3);
short c = 6;
std::cerr.write( "x = ", 4);
std::cerr.put(x);
std::cerr.put( '\n');
std::cerr << "x = " << x << std::endl;
std::cout << "a + b + c = " << std::scientific << a + b + c << " hello World" << std::endl;
std::cout << "a + b + c = " << std::fixed << a + b + c << std::endl;
std::cout << "e * f = " << e << " * " << f << "=" << e * f << std::endl;
((std::cout.write("x= ", 3)).operator<<(x)).operator<<(std::endl);
((std::cout.operator<<("x= ")).operator<<(x)).operator<<(std::endl);
std::cout << "x = " << x << std::endl;
}
[toc] | [next] | [standalone]
| From | red floyd <no.spam.here@its.invalid> |
|---|---|
| Date | 2011-05-31 21:50 -0700 |
| Message-ID | <is4gfl$b94$1@dont-email.me> |
| In reply to | #5934 |
On 5/31/2011 6:45 PM, Ruben Safir wrote:
> can simeone explain why the last 3 lines don't behave like expected
>
> #include<iomanip>
>
>
> int main(int argv, char ** argc){
>
> char x = 'm';
> float a = 3.14, b = 9.3453, e = 3, f = 1/3;
> f = (1.0 / 3);
> short c = 6;
> std::cerr.write( "x = ", 4);
> std::cerr.put(x);
> std::cerr.put( '\n');
> std::cerr<< "x = "<< x<< std::endl;
> std::cout<< "a + b + c = "<< std::scientific<< a + b + c<< " hello World"<< std::endl;
> std::cout<< "a + b + c = "<< std::fixed<< a + b + c<< std::endl;
> std::cout<< "e * f = "<< e<< " * "<< f<< "="<< e * f<< std::endl;
> ((std::cout.write("x= ", 3)).operator<<(x)).operator<<(std::endl);
> ((std::cout.operator<<("x= ")).operator<<(x)).operator<<(std::endl);
> std::cout<< "x = "<< x<< std::endl;
> }
>
Ignoring the missing #include <iostream>, exactly how were you
expecting it to behave, and what did you see instead?
Please see FAQ 5.8
[toc] | [prev] | [next] | [standalone]
| From | ruben safir <ruben@mrbrklyn.com> |
|---|---|
| Date | 2011-06-02 22:44 -0400 |
| Message-ID | <is9hq0$91p$2@reader1.panix.com> |
| In reply to | #5937 |
On 06/01/2011 12:50 AM, red floyd wrote:
> ((std::cout.operator<<("x= ")).operator<<(x)).operator<<(std::endl);
well for one thing, this one I didn't expect to get hex code.
Ruben
[toc] | [prev] | [next] | [standalone]
| From | Michael Doubez <michael.doubez@free.fr> |
|---|---|
| Date | 2011-06-03 02:56 -0700 |
| Message-ID | <c17d3309-0cd6-4b7e-8bb4-83619d622afd@16g2000yqy.googlegroups.com> |
| In reply to | #6119 |
On 3 juin, 04:44, ruben safir <ru...@mrbrklyn.com> wrote:
> On 06/01/2011 12:50 AM, red floyd wrote:
>
> > ((std::cout.operator<<("x= ")).operator<<(x)).operator<<(std::endl);
>
> well for one thing, this one I didn't expect to get hex code.
Because, the only ioperator available is:
basic_ostream<charT,traits>& operator<<(const void* p);
Which writes the pointer value (like %#p in printf).
The string version is the free function:
template<class charT, class traits>
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&
out,
const char* s);
// ... other templates cf. 27.6.2.5.4 of the standard
Which computes the length and inserts the string into the stream.
AFAIK there are no corresponding function in the std::ostream
interface (for formated output).
--
Michael
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web