mixing of std::cout and std::wcout

R

Ralf Goertz

Hi,

can I mix output to cout and wcout? It seems that if I write to cout
first it works fine but if I start with wcout the output to cout
vanishes. I assume that is has to do with the initialization of
standard output, right?

#include <iostream>

using namespace std;

int main(int argc, char *argv[]){
wcout<<L"wcout"<<endl; //(*)
cout<<"cout"<<endl;
wcout<<L"wcout"<<endl;
cout<<"cout"<<endl;
}

This gives

wcout
wcout

but if I comment out the line marked (*) the output is

cout
wcout
cout

Is that standard or is my compiler ("gcc version 4.1.2 20061115
(prerelease) (SUSE Linux)") buggy?

Ralf
 
M

Marcus Kwok

Ralf Goertz said:
#include <iostream>

using namespace std;

int main(int argc, char *argv[]){
wcout<<L"wcout"<<endl; //(*)
cout<<"cout"<<endl;
wcout<<L"wcout"<<endl;
cout<<"cout"<<endl;
}

This gives

wcout
wcout

Using VS 2005, I get the expected output:

wcout
cout
wcout
cout
Is that standard or is my compiler ("gcc version 4.1.2 20061115
(prerelease) (SUSE Linux)") buggy?

I would say it might be a problem with the compiler, or at least with
the iostream implementation. I recall hearing something about gcc not
handling wide streams correctly.
 
R

Ralf Goertz

Marcus Kwok wrote:

I would say it might be a problem with the compiler, or at least with
the iostream implementation. I recall hearing something about gcc not
handling wide streams correctly.


Meanwhile I found out that this behaviour is intended. Mixing wide and
non wide streams is not considered standard. Although one might argue
that the asymmetric gcc implementation is somewhat awkward.

http://gcc.gnu.org/ml/gcc-bugs/2006-05/msg01196.html

Thanks anyway,

Ralf
 

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,041
Latest member
RomeoFarnh

Latest Threads

Top