| View previous topic :: View next topic |
| Author |
Message |
Dave Guest
|
Posted: Sat Jan 29, 2005 10:50 pm Post subject: Narrow Vs. wide streams |
|
|
The program below is conforming according to VC++ 7.1 and Comeau online. I
would have expected a type mismatch. Am I seeing a compiler problem, or is
the observed behavior correct?
Thanks!
#include <iostream>
using namespace std;
int main()
{
// Displays a hex number under VC++ 7.1
cout << L"Hello world!" << endl;
// Displays "Hello world!" under VC++ 7.1
wcout << "Hello world!" << endl;
}
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Sat Jan 29, 2005 11:57 pm Post subject: Re: Narrow Vs. wide streams |
|
|
Efrat Regev wrote:
| Quote: | "Dave" <better_cs_now (AT) yahoo (DOT) com> wrote in message
news:10vo4ojqm9gsvbf (AT) news (DOT) supernews.com...
The program below is conforming according to VC++ 7.1 and Comeau
online. I would have expected a type mismatch. Am I seeing a
compiler problem, or is the observed behavior correct?
Thanks!
#include
using namespace std;
int main()
{
// Displays a hex number under VC++ 7.1
cout << L"Hello world!" << endl;
// Displays "Hello world!" under VC++ 7.1
wcout << "Hello world!" << endl;
}
Your operator<< call calls a method of the form
Imp &operator<<(const void *p_val)
in both cases.
|
In the first case only: narrow C-style strings can be written to any
basic_ostream: chars are widened using a ctype facet.
| Quote: | The subsequent "translation" from void * to char * or
w_char * is handled by the stream, and is independent from
what p_val originally pointed to (as far as I understand).
|
Jonathan
|
|
| Back to top |
|
 |
Efrat Regev Guest
|
Posted: Sun Jan 30, 2005 12:46 am Post subject: Re: Narrow Vs. wide streams |
|
|
"Dave" <better_cs_now (AT) yahoo (DOT) com> wrote
| Quote: | The program below is conforming according to VC++ 7.1 and Comeau online.
I
would have expected a type mismatch. Am I seeing a compiler problem, or
is
the observed behavior correct?
Thanks!
#include
using namespace std;
int main()
{
// Displays a hex number under VC++ 7.1
cout << L"Hello world!" << endl;
// Displays "Hello world!" under VC++ 7.1
wcout << "Hello world!" << endl;
}
|
Your operator<< call calls a method of the form
Imp &operator<<(const void *p_val)
in both cases. The subsequent "translation" from void * to char * or w_char
* is handled by the stream, and is independent from
what p_val originally pointed to (as far as I understand).
|
|
| Back to top |
|
 |
Efrat Regev Guest
|
Posted: Sun Jan 30, 2005 3:19 am Post subject: Re: Narrow Vs. wide streams |
|
|
"Jonathan Turkanis" <technews (AT) kangaroologic (DOT) com> wrote
| Quote: | Efrat Regev wrote:
"Dave" <better_cs_now (AT) yahoo (DOT) com> wrote in message
news:10vo4ojqm9gsvbf (AT) news (DOT) supernews.com...
The program below is conforming according to VC++ 7.1 and Comeau
online. I would have expected a type mismatch. Am I seeing a
compiler problem, or is the observed behavior correct?
Thanks!
#include
using namespace std;
int main()
{
// Displays a hex number under VC++ 7.1
cout << L"Hello world!" << endl;
// Displays "Hello world!" under VC++ 7.1
wcout << "Hello world!" << endl;
}
Your operator<< call calls a method of the form
Imp &operator<<(const void *p_val)
in both cases.
In the first case only: narrow C-style strings can be written to any
basic_ostream: chars are widened using a ctype facet.
The subsequent "translation" from void * to char * or
w_char * is handled by the stream, and is independent from
what p_val originally pointed to (as far as I understand).
Jonathan
|
Yes, you're right. Sorry for my mistaken reply.
|
|
| Back to top |
|
 |
|