Unix Programming - Why cant i mix wcout and wprintf ?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2004 > Why cant i mix wcout and wprintf ?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Why cant i mix wcout and wprintf ?
Dylan

2004-06-16, 5:57 pm

Im trying to write some code to use wide character functions under
RedHat 9
with:
gcc & g++ version 3.2.2 20030222

glibc version 2.3.2-27.9.7

The following code doesnt work properly (i couldnt cut and paste from
original code which is on another pc, i had to retype.. please excuse
syntax errors if any).

[code]
#include <unistd.h>
#include <wctype.h>
#include <wchar.h>
#include <iostream>

int main( int argc, char **argv )
{
wchar_t lh[2048];
memset( lh, 0, sizeof( wchar_t ) * 2048 );
wcscpy( lh, L"This is a WIDE string" );

wprintf( L"[WIDESTRING]: %ls", lh );
std::wcout << lh << std::endl;
printf( "This is a non-wide printf\n" );
std::cout << "Non-Wide cout" << std::endl;
wprintf( L"[WIDESTRING]: %ls", lh );


return 0;
}

[/code]

The output will be:

[code]
[WIDESTRING]: This is a WIDE string
[WIDESTRING]: This is a WIDE string
[/code]

It will not do the wcout ??

Basically it seems whatever comes first gets printed be it wcout or
wprintf, the second one wont print. Infact it seems to lock in the
first type and prevent usage of other streams ?

The problem with this is it seems to also prevent other functions such
as vswprintf() to work which is fairly annoying.

Can anyone enlighten me as to why this doesnt work or what i can do to
fix it?


Many thanks.
Thomas Dickey

2004-06-16, 5:57 pm

Dylan <dylan@fast.fujitsu.com.au> wrote:
> Im trying to write some code to use wide character functions under
> RedHat 9
> with:
> gcc & g++ version 3.2.2 20030222
>
> glibc version 2.3.2-27.9.7

....
> It will not do the wcout ??


> Basically it seems whatever comes first gets printed be it wcout or
> wprintf, the second one wont print. Infact it seems to lock in the
> first type and prevent usage of other streams ?


arguably C++ streams and C stdio should use the same underlying mechanism, but
it appears that since the C++ standard doesn't state this, some implementors
read that as implying that there's no requirement to make them work together.

(perhaps posting to comp.lang.c++ would elicit some useful information, e.g.,
the part of the C++ standard which would cover that).

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Roger Leigh

2004-06-16, 5:57 pm

On 2004-06-16, Thomas Dickey <dickey@saltmine.radix.net> wrote:
> Dylan <dylan@fast.fujitsu.com.au> wrote:
>
> arguably C++ streams and C stdio should use the same underlying mechanism, but
> it appears that since the C++ standard doesn't state this, some implementors
> read that as implying that there's no requirement to make them work together.


They should by default be synched with GNU libstdc++. If not, try

std::ios::sync_with_stdio(true);

before any cstdio or isostream use.

> (perhaps posting to comp.lang.c++ would elicit some useful information, e.g.,
> the part of the C++ standard which would cover that).


The GNU libstdc++ FAQ covers some aspects also.


--
Roger Leigh

Printing on GNU/Linux? http://gimp-print.sourceforge.net/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.


-----= Posted via mcse.ms, Uncensored Usenet News =-----
http://www.mcse.ms - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com