Greek Characters in C++ on Visual Studio 2019

Thread Starter

FuneralHomeJanitor

Joined Oct 12, 2019
30
Hi everyone I am a very inexperienced novice in the world of programming and am trying to learn C++ for practical purposes in order to create programs to quickly calculate things like equivalent resistance and other electrical engineering calculations. I would like to insert a capital omega into my output in the command prompt when it displays the resistance it calculated. I have read some stuff online but when I tried to enter in the code I needed the output in that spot was a question mark instead of the omega symbol. I tried using the "escape sequence" code for this. Is there anyone that can explain how to do this or what I maybe did wrong, or if it is even possible on Visual Studio? I have a very time understanding the jargon used to explain concepts in the world of programming and if someone could easily explain it to me like they are taking to a complete idiot that doesn't really understand programming terms I would much appreciate it. Also if anyone has advice on how I can better understand the lingo that is used in programming explanations I would very much appreciate that too. Thanks in advance.
 

Papabravo

Joined Feb 24, 2006
14,831
The appearance of the '?' symbol could be due to a couple of things. One possible explanation is that you are not using a code page that understands the encoding that you are using for the symbol. Once you exit the realm of the ASCII character set you are on terra incognito for how to encode various charaters and how they are displayed. Check out the following page for more information on possible encoding:

https://www.compart.com/en/unicode/U+03A9
 

Thread Starter

FuneralHomeJanitor

Joined Oct 12, 2019
30
The appearance of the '?' symbol could be due to a couple of things. One possible explanation is that you are not using a code page that understands the encoding that you are using for the symbol. Once you exit the realm of the ASCII character set you are on terra incognito for how to encode various charaters and how they are displayed. Check out the following page for more information on possible encoding:

https://www.compart.com/en/unicode/U+03A9
I tried everything within my understanding of programming that I could(which isn’t that much) with no success and I am starting to wonder if it is just something that can’t be done using the means I have, thanks though
 

Papabravo

Joined Feb 24, 2006
14,831
I tried everything within my understanding of programming that I could(which isn’t that much) with no success and I am starting to wonder if it is just something that can’t be done using the means I have, thanks though
I regularly use keyboard shortcuts to add Greek letters to all sorts of things, including documents, LTSpice schematics, email and so forth. From your description you are referring to a command prompt. Could you elaborate a bit on the environment you are working with. Operating system, compiler, that sort of thing.
Using the command "chcp" it seems that my machine uses code page #437 which has a captial omega at 0xEA(234 decimal)
 
Last edited:

402DF855

Joined Feb 9, 2013
255
I can confirm that my command prompt shows an upper case omega on code page 437 using code 0xEA, and a typical way of using this in code is:

printf("Omega \xEA\n");

Produces:

Omega Ω
 

djsfantasi

Joined Apr 11, 2010
7,187
I suspect that the ? You are seeing is what the C++ compiler outputs when it sees an unrecognized character.

I will have to speak generally here. What you need to do is specify a character map containing the Greek characters you need. This is called a “code page”. Every language I have encountered contains a function to set the code page when using special characters.

I performed a search using the keywords “C++ code page” and received many articles on how to do this. Try that search yourself.
 

402DF855

Joined Feb 9, 2013
255
I suspect that the ? You are seeing is what the C++ compiler outputs when it sees an unrecognized character.
Not the compiler, but rather cmd.exe trying to make sense of the code being output. You can use the Character Map to check character codes. Be warned, the topic of character sets can be very complicated. Notice the utility shows 0xEA for the Omega symbol.

1609719999375.png
 

djsfantasi

Joined Apr 11, 2010
7,187
Not the compiler, but rather cmd.exe trying to make sense of the code being output. You can use the Character Map to check character codes. Be warned, the topic of character sets can be very complicated. Notice the utility shows 0xEA for the Omega symbol.

View attachment 226677
What does cmd.exe got to do with it? It’s the C++ code that sets the code page.
 

Papabravo

Joined Feb 24, 2006
14,831
That is why I asked the TS to specify his environment. A request that he has failed to comply with. He mentions "Command Prompt" and Visual Studio, so it seems reasonable that he is attempting a console program.
 

402DF855

Joined Feb 9, 2013
255
What does cmd.exe got to do with it? It’s the C++ code that sets the code page.
I doubt it. The code page probably comes out of the registry. The compiler happily puts the characters specified in the source files in a buffer and calls library functions to output to the stdout (or where ever).
 

djsfantasi

Joined Apr 11, 2010
7,187
I doubt it. The code page probably comes out of the registry. The compiler happily puts the characters specified in the source files in a buffer and calls library functions to output to the stdout (or where ever).
And how does it know what characters to put into the buffer? And why does the code need to use a function to set the code page?
 

402DF855

Joined Feb 9, 2013
255
And how does it know what characters to put into the buffer?
It takes the characters from the source code. I posted an example earlier. According to code page 437 the upper case omega is 0xe4 so the string would be "\xE4".
And why does the code need to use a function to set the code page?
It doesn't need to. There is a default, which, as I said, likely comes from the registry. In fact, I don't see an API to set the code page. It may be there I just don't see it. There is a GetCPInfo API. If you are curious about details, look in output.c of the VC CRT, e.g. _output_l(), which is invoked through printf. It's a beast.
 

Papabravo

Joined Feb 24, 2006
14,831
It takes the characters from the source code. I posted an example earlier. According to code page 437 the upper case omega is 0xe4 so the string would be "\xE4".
It doesn't need to. There is a default, which, as I said, likely comes from the registry. In fact, I don't see an API to set the code page. It may be there I just don't see it. There is a GetCPInfo API. If you are curious about details, look in output.c of the VC CRT, e.g. _output_l(), which is invoked through printf. It's a beast.
Actually there are two default code pages. There is also a command line method for checking/changing the code page. With no argument it tells you what the default application code page is. With a numeric argument it changes the default application code page to the numeric argument. No idea if there is any argument checking.
 

402DF855

Joined Feb 9, 2013
255
Looks like you can use SetLocaleInfo to change code page and other related parameters. From the documentation:

When the ANSI version of this function is used with a Unicode-only locale identifier, the function can succeed because the operating system uses the system code page. However, characters that are undefined in the system code page appear in the string as a question mark (?).
 
Last edited:
Top