User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 375,171 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,140 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 5170 | Replies: 7 | Solved
Reply
Join Date: May 2006
Posts: 36
Reputation: CStallion is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
CStallion CStallion is offline Offline
Light Poster

Special Characters in C++

  #1  
May 17th, 2006
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:
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Location: UK
Posts: 461
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Rep Power: 5
Solved Threads: 39
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: Special Characters in C++

  #2  
May 17th, 2006
Originally Posted by CStallion
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;
}
¿umop apisdn upside down?
Reply With Quote  
Join Date: May 2006
Posts: 36
Reputation: CStallion is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
CStallion CStallion is offline Offline
Light Poster

Re: Special Characters in C++

  #3  
May 17th, 2006
So I try "\-126" and get a compile error. Any other ideas?
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,199
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 34
Solved Threads: 824
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Special Characters in C++

  #4  
May 17th, 2006
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.
Reply With Quote  
Join Date: May 2006
Posts: 2,654
Reputation: WaltP is a name known to all WaltP is a name known to all WaltP is a name known to all WaltP is a name known to all WaltP is a name known to all WaltP is a name known to all 
Rep Power: 14
Solved Threads: 217
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: Special Characters in C++

  #5  
May 18th, 2006
Originally Posted by CStallion
So I try "\-126" and get a compile error. Any other ideas?
-126 is 82 hex -- try \x82
Reply With Quote  
Join Date: Feb 2006
Location: UK
Posts: 461
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Rep Power: 5
Solved Threads: 39
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: Special Characters in C++

  #6  
May 18th, 2006
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.
¿umop apisdn upside down?
Reply With Quote  
Join Date: May 2006
Posts: 36
Reputation: CStallion is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
CStallion CStallion is offline Offline
Light Poster

Re: Special Characters in C++

  #7  
May 18th, 2006
Good! I changed my IDE font to the font "terminal" and then inserted the é straight out and everything worked fine. Thx!
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,199
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 34
Solved Threads: 824
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Special Characters in C++

  #8  
May 18th, 2006
Originally Posted by CStallion
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:56 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC