Letting C++ program show special characters such as , ,

This is a discussion on Letting C++ program show special characters such as , , within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I want my program being able to print out special characters such as , , , , ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    36

    Letting C++ program show special characters such as , ,

    Hey guys, I want my program being able to print out special characters such as , , , , ... and so on. I know I can do this by:

    Code:
    #include <iostream>
    
    int main()
    {
        std::cout << static_cast<char> (-126); // This would print out the character .
    }
    So, -126 is the number for . What I can't figure out is, what number is for "" f.x. Help?

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    std::cout << (int)L'&#254;';
    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.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    36
    Quote Originally Posted by Elysia View Post
    std::cout << (int)L'';
    If I do that, my compiler, Code::Blocks says: "converting to execution character set: Illegal byte sequence"

    Any other ideas?

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    I suspect you aren't using unicode files. Visual Studio compiles it fine (as it should), and gives the result 254.
    But you should probably use a constant:

    const wchar_t MySymbol = L'&#254;';
    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. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    36
    I'm running Code::Blocks and I just have those lines of code which I told you first about.

    I think this has something to do with the font the cmd is using, I tried letting it print with the number 254 like you told me about, an it returned a box (in cmd). So, do I have to tell the program to use different font for this character?

    Another thing, I tried typing &#254; into cmd and it came _. Also, If I tried writing &#240;, it came d. So it's pretty sure to me it has something to do with the font. But how to fix this?

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Did you print a unicode character as opposed to a char?
    Ie
    std::cout << (wchar_t)254;
    ...instead of...
    std::cout << (char)254;
    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.

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    36
    If I do std::cout << static_cast<wchar> (254), it says that "wchar" was not declared

    Also, std::cout << (wchar_t)254 just gives me "254"
    Last edited by Helgso; 11-30-2008 at 09:30 AM.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Hmm, I think I remember that GCC does not fully support unicode. You may have to change compiler.
    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.

  9. #9
    Registered User
    Join Date
    Nov 2008
    Posts
    36
    Quote Originally Posted by Elysia View Post
    Hmm, I think I remember that GCC does not fully support unicode. You may have to change compiler.
    Any clues what compiler?

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Visual C++ is another popular one.
    (Comes with Visual Studio.)
    Code::Blocks can utilize that compiler, as well, if you don't want to use the IDE.
    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. #11
    Registered User
    Join Date
    Nov 2008
    Posts
    36
    How would I utilize Code::Blocks to do that?

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Someone else should know. Code::Blocks is not my IDE of choice and thus I am not very familiar with it.
    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.

  13. #13
    Registered User
    Join Date
    Nov 2008
    Posts
    36
    Allright, I'm installing Visual Studio. All I have to do is to copy+paste my program into that compiler, let it compile and I'm good?

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    It should. It works for me.
    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. #15
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    I've struggled a lot with this as well... It seems that the Windows terminal works on UTF-32, while the Linux terminal works on UTF-8. Try this, for instance, to show a few characters:

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
            cout << "\xe2\x82\xac\xc2\xb6\xc3\xbf" << endl;
    }
    Last edited by EVOEx; 11-30-2008 at 10:35 AM.

Page 1 of 4 1234 LastLast
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, 10:17 PM
  2. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  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, 05: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, 05:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21