By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,233 Members | 1,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,233 IT Pros & Developers. It's quick & easy.

Narrow Vs. wide streams

P: n/a
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;
}
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Dave" <be***********@yahoo.com> wrote in message
news:10*************@news.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 <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;
}


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).
Jul 23 '05 #2

P: n/a
Efrat Regev wrote:
"Dave" <be***********@yahoo.com> wrote in message
news:10*************@news.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 <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;
}
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
Jul 23 '05 #3

P: n/a
"Jonathan Turkanis" <te******@kangaroologic.com> wrote in message
news:36*************@individual.net...
Efrat Regev wrote:
"Dave" <be***********@yahoo.com> wrote in message
news:10*************@news.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 <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;
}


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.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.