If compiled without errors. I could not reproduce your error. However the string prints exactly as written. I then added the following compiler option:
-fwide-exec-charset=UTF-16
The string then appeared as a blank. I suspect that console mode apps to not handle all UTF-16 characters. But to be honest, it came out blank regardless of what I put in the string!
I wrote the string in " " which were treadition chinese. Not the string as what we see on this web page. Please look at the following link: http://ysla.myweb.hinet.net/wchar_t.jpg
I have tried to complie the code by BCC and VC..etc. Those were complied without error.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2005-06-15
Show your full compile log. Did you try setting the -fwide-exec-charset option?
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not an active member here. Hope my answer is not too late.
To solve your problem, you have to understand two things:
Microsoft didn't make much effort in making DOS window (or DOS console, emulator or whatever you like) work inside Windows, both 9x family and NT family. Therefore, DOS console is not Unicode-based and in my opinion will never support Unicode. So no need to search for answer in Unicode for DOS.
DOS console is still partly (or mostly?) 8-bit just like the old DOS before Win95. As a consequence, its display stream only accepts 8-bit data.
So, point 1 means that you have to look for the corresponding value of those two characters in the specific encoding. In traditional Chinese window, the encoding is the old Big-5 and so is for DOS. And in Big-5, those two characters' values are B4FA B8D5 in hexadecimal. But these two groups of data are 16-bit each, and because of point 2, you have to transmit 8-bit data to DOS display stream to have the correct output. That means you have to change two groups of 16-bit to 4 groups of 8-bit.
Hope you just doing "test" in DOS as you've written, but not really writing programmes for DOS. Without Unicode, it's really a great pain. But good luck anyway.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yes,I did set -fwide-exec-charset:UTF-16. It was same error message. It will be no complie problem if I set to UTF-8. But it appeared the string as blank.
compile log with Default setting as following:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
main.cpp:8:18: converting to execution character set: Illegal byte sequence
make.exe: *** [main.o] Error 1
Execution terminated
complie log with UTF-16 setting as following:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make clean
rm -f main.o 專案1.exe
Dear all,
my problem code are as below:
wchar_t sz[]=L"測試"; // compile with problem
inside " " are treadition chinese. After compilied,the compile log been shown "converting to execution character set: Illegal byte sequence".
wchar_t sz[]=L"string"; // compile no problem
it will be no problem if I am using English character inside " ".
any solution?
I wrote the folllowing code:
include <cstdio>
include <cstdlib>
wchar_t sz[]=L"測試";
int main()
{
wprintf( sz ) ;
system( "pause" ) ;
}
If compiled without errors. I could not reproduce your error. However the string prints exactly as written. I then added the following compiler option:
-fwide-exec-charset=UTF-16
The string then appeared as a blank. I suspect that console mode apps to not handle all UTF-16 characters. But to be honest, it came out blank regardless of what I put in the string!
I looked arount further, and found this: http://www.thozie.de/development/unicode_console.htm. The conclusion seems to be that UNICODE support for console output is limited.
Good luck!
Clifford
Cliford,
Thanks for your replied.
I wrote the string in " " which were treadition chinese. Not the string as what we see on this web page. Please look at the following link: http://ysla.myweb.hinet.net/wchar_t.jpg
I have tried to complie the code by BCC and VC..etc. Those were complied without error.
Show your full compile log. Did you try setting the -fwide-exec-charset option?
Clifford
I am at a loss. I did find this book, which contains a section on console mode apps. http://www.stolin-software.com/04booklist/0-7356-1583-7.html
Clifford
A further thought has ocurred; what OS are you using? Unicode is not fully supported in Win9x
Clifford
my OS are winxp homeedition and win2000 professional.
I'm not an active member here. Hope my answer is not too late.
To solve your problem, you have to understand two things:
Microsoft didn't make much effort in making DOS window (or DOS console, emulator or whatever you like) work inside Windows, both 9x family and NT family. Therefore, DOS console is not Unicode-based and in my opinion will never support Unicode. So no need to search for answer in Unicode for DOS.
DOS console is still partly (or mostly?) 8-bit just like the old DOS before Win95. As a consequence, its display stream only accepts 8-bit data.
So, point 1 means that you have to look for the corresponding value of those two characters in the specific encoding. In traditional Chinese window, the encoding is the old Big-5 and so is for DOS. And in Big-5, those two characters' values are B4FA B8D5 in hexadecimal. But these two groups of data are 16-bit each, and because of point 2, you have to transmit 8-bit data to DOS display stream to have the correct output. That means you have to change two groups of 16-bit to 4 groups of 8-bit.
The following programme works for me:
include <cstdio>
include <cstdlib>
wchar_t sz[]=L"\xB4\xFA\xB8\xD5";
int main() {
wprintf( sz ) ;
system( "pause" ) ;
}
Hope you just doing "test" in DOS as you've written, but not really writing programmes for DOS. Without Unicode, it's really a great pain. But good luck anyway.
yes,I did set -fwide-exec-charset:UTF-16. It was same error message. It will be no complie problem if I set to UTF-8. But it appeared the string as blank.
compile log with Default setting as following:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
main.cpp:8:18: converting to execution character set: Illegal byte sequence
make.exe: *** [main.o] Error 1
Execution terminated
complie log with UTF-16 setting as following:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make clean
rm -f main.o 專案1.exe
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -fwide-exec-charset=UTF-16
main.cpp:8:18: converting to execution character set: Illegal byte sequence
make.exe: *** [main.o] Error 1
Execution terminated