Thread: Letting C++ program show special characters such as æ, þ, ó

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Internationalization is a pain in C/C++ right now.
    The next C++ standard should help this along the way a bit.
    Unicode is not at all what it is supposed to be...

    Just note that chars are not the best for this purpose, since they can only hold a limited range of characters... it's better to use unicode, but unicode isn't properly implemented in gcc...

    I'm not really an expert in this field.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Nov 2008
    Posts
    36
    Well, I'm trying out Visual C++ for the first time and let's see if it works! Hopefully when compiled with Visual, it will return a þ but not a box like in Code::Blocks compiled exe ...

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Elysia
    It should. It works for me.
    What exactly did you try?

    Currently, these two code samples produce the same respective output when compiled with the MinGW port of g++ 3.4.5 and MSVC8 on MS Windows XP:
    Code:
    #include <iostream>
    
    int main()
    {
        std::cout << static_cast<char>(-126);
    }
    Code:
    #include <iostream>
    
    int main()
    {
        std::cout << static_cast<int>(L'&#254;');
    }
    I believe the deficiency of g++ is the lack of implementation of the wide I/O stream facilities, but that is not necessarily the same issue as a deficiency with Unicode. Unfortunately, I am also far from an expert on Unicode.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Actually, I know now I was referring to that it works to get the number (ie (int)L'&#254;').
    I didn't actually compile and get the output.
    But I know it's possible. I have done it before, but I don't remember how.
    I cannot reproduce it at this moment.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    So gcc doesn't support unicode? Googling doesn't give much information. Except for ggc + linux

  6. #21
    Registered User
    Join Date
    Nov 2008
    Posts
    36
    Quote Originally Posted by C_ntua View Post
    So gcc doesn't support unicode? Googling doesn't give much information. Except for ggc + linux
    Yeah, you're right.

    --------

    @ Elysa: Wait a second, are you telling me that the code you gave me to find the number for &#254; and print it out might be wrong code?

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by C_ntua
    So gcc doesn't support unicode?
    The MinGW port of g++ does not support wide I/O streams. I am not sure what does it mean for a compiler to support Unicode.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by C_ntua View Post
    So gcc doesn't support unicode? Googling doesn't give much information. Except for ggc + linux
    Does gcc in Windows actually produce the same results, then?

  9. #24
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by EVOEx
    Does gcc in Windows actually produce the same results, then?
    As stated in post #18, I get the same corresponding results for the MinGW port of g++ 3.4.5 and MSVC8 (Visual Studio 2005 Professional) on Windows XP for the two sample programs that I listed.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #25
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, it pretty much means that wide characters are out of the picture...
    But since there is UTF-8 and other UTFs may be implemented as multiple 1-bytes, there can, and are, 3rd party libraries out there for unicode support.
    But chars in the language aren't unicode, though. They weren't meant to support them either, but it is possible to use them in conjunction with Windows API.
    This much I know.

    Quote Originally Posted by Helgso View Post
    @ Elysa: Wait a second, are you telling me that the code you gave me to find the number for &#254; and print it out might be wrong code?
    Btw, sorry if it doesn't work and I lead you on a goose chase, and even had you install another compile and IDE.
    The current lack of support for unicode makes things like this difficult and I guess it has affected us.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by laserlight View Post
    As stated in post #18, I get the same corresponding results for the MinGW port of g++ 3.4.5 and MSVC8 (Visual Studio 2005 Professional) on Windows XP for the two sample programs that I listed.

    Ok, but did you use the same editors?
    See, some editors save their data in UTF-8, others in UTF-32, others in UTF-16, maybe. I think you'll need UTF-32 for your code.

    I really doubt it has anything to do with gcc, but of course, I might be wrong. I am often enough .

  12. #27
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by EVOEx
    Ok, but did you use the same editors?
    See, some editors save their data in UTF-8, others in UTF-32, others in UTF-16, maybe. I think you'll need UTF-32 for your code.
    I explicitly saved the code in UTF-8 for compiling in g++ and used the default encoding for Visual Studio.

    Quote Originally Posted by EVOEx
    I really doubt it has anything to do with gcc
    I think so too, at least from my experimentation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #28
    Registered User
    Join Date
    Nov 2008
    Posts
    36
    Quote Originally Posted by Elysia View Post
    Btw, sorry if it doesn't work and I lead you on a goose chase, and even had you install another compile and IDE.
    The current lack of support for unicode makes things like this difficult and I guess it has affected us.
    Yeah, I tried Visual Studio but it did the same as Code::blocks,

    returned 254 when = "cout << (wchar_t)254;"
    returned "a box" when = "cout << (char)254;"

    The "box" is like a character that is printed when a program doesn't recognize it. So, in this case, Visual did nothing better than Code::Blocks.

    But is it even possible to use this method to print characters such as &#254;, &#211; and so on, is there another method or is this simply not possible?

  14. #29
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It should be possible. I did it once. But I don't remember how. All my tests failed.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #30
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Looking through the net, it seems to be a common problem displaying this characters to Windows console. In linux most people seem to use locale.h to do the job

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  3. Results for the Encryption Contest -- June 23, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 07-07-2002, 08:04 AM
  4. Replies: 1
    Last Post: 03-12-2002, 06:31 AM
  5. Program to show the number of occurrences of words...
    By Nutshell in forum C Programming
    Replies: 5
    Last Post: 01-26-2002, 06:44 PM