473,769 Members | 6,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wcout, wprintf() only print English

Has anyone actually managed to print non-English text by using wcout or
wprintf and the rest of standard, wide character functions?
Feb 23 '08 #1
44 4384
Ioannis Vranos wrote:
Has anyone actually managed to print non-English text by using wcout or
wprintf and the rest of standard, wide character functions?

For example:

[john@localhost src]$ cat main.cc
#include <iostream>

int main()
{
using namespace std;

wcout<< L"Äïêéìáóôéê ü ìÞíõìá\n";
}

[john@localhost src]$ ./foobar-cpp
??????????? ??????

[john@localhost src]$
Feb 23 '08 #2
Ioannis Vranos wrote:
Ioannis Vranos wrote:
>Has anyone actually managed to print non-English text by using wcout or
wprintf and the rest of standard, wide character functions?


For example:

[john@localhost src]$ cat main.cc
#include <iostream>

int main()
{
using namespace std;

wcout<< L"Î”Î¿ÎºÎ¹Î¼Î±Ï ƒÏ„ικό μήνυμα\n" ;
Are you sure that you stored your source file in the same encoding the
compiler expects as source character set?
}

[john@localhost src]$ ./foobar-cpp
??????????? ??????

[john@localhost src]$
Feb 23 '08 #3
Rolf Magnus wrote:
Ioannis Vranos wrote:
>Ioannis Vranos wrote:
>>Has anyone actually managed to print non-English text by using wcout or
wprintf and the rest of standard, wide character functions?

For example:

[john@localhost src]$ cat main.cc
#include <iostream>

int main()
{
using namespace std;

wcout<< L"Î”Î¿ÎºÎ¹Î¼Î±Ï ƒÏ„ικό μήνυμα\n" ;

Are you sure that you stored your source file in the same encoding the
compiler expects as source character set?
>}

[john@localhost src]$ ./foobar-cpp
??????????? ??????

[john@localhost src]$

Well I created the file with anjuta editor with the message being a
Greek one. The Greek message also appears the same when I display the
source file in the console.

I suppose it is saved as UTF8.
Also the code

#include <iostream>
#include <string>

int main()
{
using namespace std;

wstring s;

wcin>s;
wcout<< s<< endl;
}
displays nothing when I enter greek text.
Should I mess with locales?
Feb 23 '08 #4
Ioannis Vranos wrote:
Rolf Magnus wrote:
>Ioannis Vranos wrote:
>>Ioannis Vranos wrote:
Has anyone actually managed to print non-English text by using wcout or
wprintf and the rest of standard, wide character functions?

For example:

[john@localhost src]$ cat main.cc
#include <iostream>

int main()
{
using namespace std;

wcout<< L"Î”Î¿ÎºÎ¹Î¼Î±Ï ƒÏ„ικό μήνυμα\n" ;

Are you sure that you stored your source file in the same encoding the
compiler expects as source character set?
>>}

[john@localhost src]$ ./foobar-cpp
??????????? ??????

[john@localhost src]$


Well I created the file with anjuta editor with the message being a
Greek one. The Greek message also appears the same when I display the
source file in the console.

I suppose it is saved as UTF8.
Also the code

#include <iostream>
#include <string>

int main()
{
using namespace std;

wstring s;

wcin>s;
wcout<< s<< endl;
}
displays nothing when I enter greek text.

both in g++ under Linux and VC++ 2008 Express under Windows, with the
latest saving the source code file as Unicode after it detected
non-english text.

Should I mess with locales?
Feb 23 '08 #5
Made more precise:

Ioannis Vranos wrote:
>>>For example:

[john@localhost src]$ cat main.cc
#include <iostream>

int main()
{
using namespace std;

wcout<< L"Äïêéìáóôéê ü ìÞíõìá\n";

Are you sure that you stored your source file in the same encoding the
compiler expects as source character set?

}

[john@localhost src]$ ./foobar-cpp
?????????? ? ??????

[john@localhost src]$


Well I created the file with anjuta editor with the message being a
Greek one. The Greek message also appears the same when I display the
source file in the console.

I suppose it is saved as UTF8.
Also the code

#include <iostream>
#include <string>

int main()
{
using namespace std;

wstring s;
wcin>s;

wcout<< s<< endl;
}

displays the Greek text when I enter it, but outputs nothing. With
English text, the text is displayed both when entered and outputed.
[john@localhost src]$ ./foobar-cpp
Äïêéìáóôéêü

[john@localhost src]$ ./foobar-cpp
Test
Test
[john@localhost src]$


both in g++ under Linux and VC++ 2008 Express under Windows, with the
latest saving the source code file as Unicode after it detected
non-english text.

>Should I mess with locales?
Feb 23 '08 #6
Ioannis Vranos wrote:
Ioannis Vranos wrote:
>Has anyone actually managed to print non-English text by using wcout
or wprintf and the rest of standard, wide character functions?


For example:

[john@localhost src]$ cat main.cc
#include <iostream>

int main()
{
using namespace std;

wcout<< L"Äïêéìáóôéê ü ìÞíõìá\n";
}

[john@localhost src]$ ./foobar-cpp
??????????? ??????

[john@localhost src]$
Hmmm... I work almost entirely in English, so this error message is new
to me:

$ make
g++ -ansi -pedantic -Wall main.cc -o main
main.cc: In function 'int main()':
main.cc:4: error: converting to execution character set: Invalid or
incomplete multibyte or wide character
make: *** [main] Error 1
Feb 23 '08 #7
On Sat, 23 Feb 2008 13:11:09 +0200, Ioannis Vranos
<iv*****@nospam .no.spamfreemai l.grwrote:
[...]
>>Also the code
[...]displays the Greek text when I enter it, but outputs nothing. With
English text, the text is displayed both when entered and outputed.
I don't remember anymore the details but the problem has something to do
with codecvt: Your wide characters are automatically converted to narrow
characters by wcout. This is something you might not want (and even if you
want it the conversion might not work automatically the way you expect :).

Try writing to wstringstream and converting to UTF-8 explicitly (storing
the result eg. in string). If your console supports UTF-8 you can print to
cout (otherwise print to a file so you can test the output in an editor).

HTH,
Boris
Feb 23 '08 #8
Jeff Schwab wrote:
Ioannis Vranos wrote:
>Ioannis Vranos wrote:
>>Has anyone actually managed to print non-English text by using wcout
or wprintf and the rest of standard, wide character functions?


For example:

[john@localhost src]$ cat main.cc
#include <iostream>

int main()
{
using namespace std;

wcout<< L"Äïêéìáà ³Ã´Ã©ÃªÃ¼ ìÞÃ*õìá\n" ;
}

[john@localhost src]$ ./foobar-cpp
??????????? ??????

[john@localhost src]$

Hmmm... I work almost entirely in English, so this error message is new
to me:

$ make
g++ -ansi -pedantic -Wall main.cc -o main
main.cc: In function 'int main()':
main.cc:4: error: converting to execution character set: Invalid or
incomplete multibyte or wide character
make: *** [main] Error 1

I tried the same:

[john@localhost src]$ g++ -ansi -pedantic-errors -Wall main.cc -o
foobar-cpp

[john@localhost src]$
Perhaps when you copy and paste the greek text, you copy garbage (that
is, not viewing the message in the correct character set in your
newsgroup reader).
So, I repost the code in this message which is encoded to Unicode (UTF-8):
#include <iostream>

int main()
{
using namespace std;

wcout<< L"Î”Î¿ÎºÎ¹Î¼Î±Ï ƒÏ„ικό μήνυμα\n" ;
}
Feb 23 '08 #9
Ioannis Vranos wrote:
Jeff Schwab wrote:
>Ioannis Vranos wrote:
>>Ioannis Vranos wrote:
Has anyone actually managed to print non-English text by using wcout
or wprintf and the rest of standard, wide character functions?
For example:

[john@localhost src]$ cat main.cc
#include <iostream>

int main()
{
using namespace std;

wcout<< L"Äïêéìáà ³Ã´Ã©ÃªÃ¼ ìÞÃ*õìá\n" ;
}

[john@localhost src]$ ./foobar-cpp
??????????? ??????

[john@localhost src]$

Hmmm... I work almost entirely in English, so this error message is
new to me:

$ make
g++ -ansi -pedantic -Wall main.cc -o main
main.cc: In function 'int main()':
main.cc:4: error: converting to execution character set: Invalid or
incomplete multibyte or wide character
make: *** [main] Error 1


I tried the same:

[john@localhost src]$ g++ -ansi -pedantic-errors -Wall main.cc -o
foobar-cpp

[john@localhost src]$
Perhaps when you copy and paste the greek text, you copy garbage (that
is, not viewing the message in the correct character set in your
newsgroup reader).
So, I repost the code in this message which is encoded to Unicode (UTF-8):
#include <iostream>

int main()
{
using namespace std;

wcout<< L"Î”Î¿ÎºÎ¹Î¼Î±Ï ƒÏ„ικό μήνυμα\n" ;
}
Thanks, you were correct.

Here's what I thought was "supposed" to be the portable solution:

#include <iostream>
#include <locale>

int main() {
std::wcout.imbu e(std::locale(" el_GR.UTF-8"));
std::wcout << L"Î”Î¿ÎºÎ¹Î¼Î±Ï ƒÏ„ικό μήνυμα\n" ;
}

However, my system still shows question marks for this. For whatever
it's worth, here's the (probably incorrect) way that appears to work on
my system:

#include <iostream>
#include <locale>

int main() {
std::cout.imbue (std::locale("" ));
std::cout << "Δοκιμασ τικό μήνυμα\n" ;
}
Feb 23 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.