Is std::wcout really required?

A

Amit Kumar

Output of all the four statements are the same on Visual studio:

std::cout << "Hello\n";
std::wcout << "Hello\n";
std::cout << L"Hello\n";
std::wcout << L"Hello\n";

If cout and wcout can handle both char strings and wide char strings
then why do we need wcout?
 
T

Thomas Matthews

Amit said:
Output of all the four statements are the same on Visual studio:

std::cout << "Hello\n";
std::wcout << "Hello\n";
std::cout << L"Hello\n";
std::wcout << L"Hello\n";

If cout and wcout can handle both char strings and wide char strings
then why do we need wcout?

Yes, wcout is required since changing the functionality of cout
would screw up a bunch of legacy programs.

However, there is nothing stopping _you_ from overloading
cout to perform the way _you_ think it should.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
B

Bo Persson

Amit said:
Output of all the four statements are the same on Visual studio:

std::cout << "Hello\n";
std::wcout << "Hello\n";
std::cout << L"Hello\n";
std::wcout << L"Hello\n";

If cout and wcout can handle both char strings and wide char strings
then why do we need wcout?

No, the results are not the same. Outputting a wide string to cout
differs from the others.

On recent versions of Windows, the question is "Why do we need cout,
when wcout works for both narrow and wide strings?".

On other systems, the question might be different.


Bo Persson
 
D

Donkey Hottie

Bo Persson said:
On recent versions of Windows, the question is "Why do we
need cout, when wcout works for both narrow and wide
strings?".
On other systems, the question might be different.

So why the Windows implementation defines a new wcout, and not re-define
cout in the first place?
 
B

Bo Persson

Donkey said:
So why the Windows implementation defines a new wcout, and not
re-define cout in the first place?

It is not new, they are both in the language standard. It is just that
as newer Windows versions internally uses wchar_t for characters,
wcout is a better match.


Bo Persson
 
A

Alf P. Steinbach

* Bo Persson:
It is not new, they are both in the language standard. It is just that
as newer Windows versions internally uses wchar_t for characters,
wcout is a better match.

I'm not sure I understand what you're talking about.

Could you sort of elaborate?
 
B

Bo Persson

Alf said:
* Bo Persson:

I'm not sure I understand what you're talking about.

Could you sort of elaborate?

I'm not sure I understand what you don't understand.

Is it the design to use a 16-bit character set in the OS, but keep
char and cout 8-bit wide? Or is it my preference of using wcout for
the occational console output, taking advantage of a 1-to-1 mappning
to the resulting byte stream?


Bo Persson
 
A

Alf P. Steinbach

* Bo Persson:
I'm not sure I understand what you don't understand.

Is it the design to use a 16-bit character set in the OS, but keep
char and cout 8-bit wide?

No, I understand that well.

It was done in a stupid way that made console windows effectively incompatible
with the rest of Windows, for the ordinary end user.

Or is it my preference of using wcout for
the occational console output, taking advantage of a 1-to-1 mappning
to the resulting byte stream?

There is no 1-to-1 mapping.

It is mapping that *loses* information.

Even if you use some non-standard UTF-8 "locale" you're screwed, because in
Windows XP the UTF-8 codepage, 65001, does not work. "Does not work" means, for
example, that ordinary commands stop having any effect when you switch to this
codepage (and e.g. the 'more' command will, silly enough, report that it's out
of memory). So it "can't" be used for output until Windows XP is well dead.


Cheers & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top