I need to insert a "é" and other such symbols. At first I just tried using é straight out in C++ and it returned Θ. So I looked at my character map and did the unicode version \u00E9 where I wanted the é and it still returned Θ. I guess they are using two different standards. Can anyone point me to a list of such common special characters and their c++ encodings? My attempts at a google search have been inconclusive. Thanks :cheesy:

I need to insert a "é" and other such symbols. At first I just tried using é straight out in C++ and it returned Θ. So I looked at my character map and did the unicode version \u00E9 where I wanted the é and it still returned Θ. I guess they are using two different standards. Can anyone point me to a list of such common special characters and their c++ encodings? My attempts at a google search have been inconclusive. Thanks :cheesy:

There's nothing standard about extended ASCII characters. the extended ASCII code for that character in your IDE's font is obviously different to the code in your output console's font.

using this code, the character é yields a value of -126 on my system

#include <iostream>

int main()
{
    char c;
    std::cin.get(c);
    std::cout << static_cast<int> c;
}

So I try "\-126" and get a compile error. Any other ideas?

I think you're c++ program will have to change fonts before beginning to output the text. The font used by the c++ console program is not the same font that the IDE editor uses. The IDE does not use cout or other console output functions to write to the window -- it uses win32 api functions. Don't know how to do that in console program.

So I try "\-126" and get a compile error. Any other ideas?

-126 is 82 hex -- try \x82

So I try "\-126" and get a compile error. Any other ideas?

"\-126" isn't a char, the double quotes translate that you are attempting to use a string literal, which isn't what you want. There should be no need for the backslash either, since you're not using an escape character.

Just to re-iterate, this is not a C++ issue, this is an implementation-specific font issue. The windows 2000 cmd.exe console uses the "Terminal" font, hence why I got a value of -126 (or 0x82) for the 'é' character. if your implementation uses a different font, there's a strong possibility that the number -126 is not what you need (The code in my earlier post is indifferent to the font)

rambling aside - here is how you might print the é character, if your output uses the Terminal font.

#include <iostream>

int main()
{
    char c = -126;
         // you could also use 0x82 instead of -126
    std::cout << c;
}

or..

#include <iostream>

int main()
{
    std::cout << static_cast<char> (-126);
}

You may also be able to change your IDE to use the same font as your console window, although I haven't tested that idea.

Good! I changed my IDE font to the font "terminal" and then inserted the é straight out and everything worked fine. Thx!

Good! I changed my IDE font to the font "terminal" and then inserted the é straight out and everything worked fine. Thx!

What? I thought you wanted to see 'é', not that other character. When I did that with Dev-C++ it only made the IDE look like the console, not the other way around.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.