cout for japanese messages
-
Hi, I am trying out the following code .
setlocale(LC_ALL ,"");
std::string ab = "名前を入力してください: " ;cout.imbue(std::locale("Japanese_Japan.932"));
cout<<ab<<endl; // No message seen on console
printf("%s" ,ab.c_str());// this statement is printing the messageBoth system and user locale are set to japanese. Cout statement doesnt print the message in screen. I am able to print message using printf . how can i use cout to print japanese meesages ? Thanks in advance
-
Hi, I am trying out the following code .
setlocale(LC_ALL ,"");
std::string ab = "名前を入力してください: " ;cout.imbue(std::locale("Japanese_Japan.932"));
cout<<ab<<endl; // No message seen on console
printf("%s" ,ab.c_str());// this statement is printing the messageBoth system and user locale are set to japanese. Cout statement doesnt print the message in screen. I am able to print message using printf . how can i use cout to print japanese meesages ? Thanks in advance
shouldn't you use
std::wstring
? -
shouldn't you use
std::wstring
?Maximilien wrote:
shouldn't you use std::wstring
No. His encoding is Shift_JIS (CP 932) and that's multibyte, not wide char.
-
Hi, I am trying out the following code .
setlocale(LC_ALL ,"");
std::string ab = "名前を入力してください: " ;cout.imbue(std::locale("Japanese_Japan.932"));
cout<<ab<<endl; // No message seen on console
printf("%s" ,ab.c_str());// this statement is printing the messageBoth system and user locale are set to japanese. Cout statement doesnt print the message in screen. I am able to print message using printf . how can i use cout to print japanese meesages ? Thanks in advance
Are you sure the locale was successfully set? Try
cout << cout.rdbuf()->getloc().name();
after the
imbue
and see what it prints out. -
Are you sure the locale was successfully set? Try
cout << cout.rdbuf()->getloc().name();
after the
imbue
and see what it prints out.As you said i tried printing the stream locale is shows "Japanese_Japan.932". One thing observed is that if setlocale(LC_ALL ,"") call is commented then the message is printed correctly. Any idea why ?
-
Maximilien wrote:
shouldn't you use std::wstring
No. His encoding is Shift_JIS (CP 932) and that's multibyte, not wide char.
Nemanja Trifunovic wrote:
No. His encoding is Shift_JIS (CP 932) an
No. Her* encoding is... ;P *Deepa = female
It is a crappy thing, but it's life -^ Carlo Pallini
-
As you said i tried printing the stream locale is shows "Japanese_Japan.932". One thing observed is that if setlocale(LC_ALL ,"") call is commented then the message is printed correctly. Any idea why ?
Deepa Bellary wrote:
setlocale(LC_ALL ,"")
What is the User default ANSI code page of your operating system? If that is the same as the code page of what you're trying to print, I don't see why it should fail. From the docs ^:
setlocale( LC_ALL, "" );
Sets the locale to the default, which is the user-default ANSI code page obtained from the operating system.It is a crappy thing, but it's life -^ Carlo Pallini
-
Nemanja Trifunovic wrote:
No. His encoding is Shift_JIS (CP 932) an
No. Her* encoding is... ;P *Deepa = female
It is a crappy thing, but it's life -^ Carlo Pallini
I should know you're only interested in female's questions. ;P :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I should know you're only interested in female's questions. ;P :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Wait... Weren't you the same guy who accused me of having a general hatred towards women? ;P
It is a crappy thing, but it's life -^ Carlo Pallini
-
Hi, I am trying out the following code .
setlocale(LC_ALL ,"");
std::string ab = "名前を入力してください: " ;cout.imbue(std::locale("Japanese_Japan.932"));
cout<<ab<<endl; // No message seen on console
printf("%s" ,ab.c_str());// this statement is printing the messageBoth system and user locale are set to japanese. Cout statement doesnt print the message in screen. I am able to print message using printf . how can i use cout to print japanese meesages ? Thanks in advance
If you are using std::wstring's, you need std::wcout. std::cout works *only* with std::strings. Since there is no _tcout, I like to use _tprintf (and _T macro) when printing Unicode stuff in console. Take this code for example: std::wstring test1 = _T("test1"); std::cout << test1.c_str() << endl; // prints junk "0012DE10" std::wcout << test1.c_str() << endl; // prints "test1" But to do it "properly", something like this is needed: std::basic_string<TCHAR> test1 = _T("test1"); _tprintf(_T("Testing string is: %s"), test1.c_str()); I hope that helps. Best regards, loreia
modified on Saturday, January 17, 2009 12:55 PM
-
Wait... Weren't you the same guy who accused me of having a general hatred towards women? ;P
It is a crappy thing, but it's life -^ Carlo Pallini
Yes. :-O Your memory is too strong, pal. :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, I am trying out the following code .
setlocale(LC_ALL ,"");
std::string ab = "名前を入力してください: " ;cout.imbue(std::locale("Japanese_Japan.932"));
cout<<ab<<endl; // No message seen on console
printf("%s" ,ab.c_str());// this statement is printing the messageBoth system and user locale are set to japanese. Cout statement doesnt print the message in screen. I am able to print message using printf . how can i use cout to print japanese meesages ? Thanks in advance
The problem was with Vc++ 2005 on windows XP .Please refer to this link http://support.microsoft.com/kb/927753[^]
-
Yes. :-O Your memory is too strong, pal. :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]CPallini wrote:
Your memory is too strong, pal.
Mr. Nic Rowan shares his opinion[^] with you. :-\
It is a crappy thing, but it's life -^ Carlo Pallini
-
CPallini wrote:
Your memory is too strong, pal.
Mr. Nic Rowan shares his opinion[^] with you. :-\
It is a crappy thing, but it's life -^ Carlo Pallini
Uh?!... What opinion? :-D :laugh: :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, I am trying out the following code .
setlocale(LC_ALL ,"");
std::string ab = "名前を入力してください: " ;cout.imbue(std::locale("Japanese_Japan.932"));
cout<<ab<<endl; // No message seen on console
printf("%s" ,ab.c_str());// this statement is printing the messageBoth system and user locale are set to japanese. Cout statement doesnt print the message in screen. I am able to print message using printf . how can i use cout to print japanese meesages ? Thanks in advance
use wprintf() instead of printf(). likely use wide char version of cout(wcout) instead of cout