21

I have a small console based application that will solve physics equations. I am trying to ask the user if they want to find the ΔV in a given situation, but I can't figure out how to print the letter delta to the console. Here's my code:

cout << "Select what you would like to find:\n"
<< "1 - Acceleration" << endl
<< "2 - Initial Velocity" << endl
<< "3 - Final Velocity" << endl
<< "4 -  ΔV" << "\n\n";
cin >> choice;

This does not print "ΔV" to the console. The "Δ" doesn't even display in my IDE (Dev-C++), instead being displayed as a question mark. If anyone knows how I can print Δ to the console I would highly appreciate any help you can give me.

Thanks in advance!

101010
  • 41,839
  • 11
  • 94
  • 168
Will Callender
  • 356
  • 1
  • 2
  • 8
  • 5
    Welcome to the awful world of text encoding. Good luck getting an answer but I expect this might be surprisingly awkward based on your system config and compiler. – Vality Oct 26 '16 at 21:45
  • Half the duplicate: [How to print Unicode character in C++?](http://stackoverflow.com/questions/12015571/how-to-print-unicode-character-in-c) – user4581301 Oct 26 '16 at 21:46
  • 2
    oh boy howdy are you in for a ride – jaggedSpire Oct 26 '16 at 21:46
  • Oh come on, folks. It's much easier than it used to be. We no longer have so sacrifice our first-born. – user4581301 Oct 26 '16 at 21:48
  • 2
    @user4581301 just our second-born – jaggedSpire Oct 26 '16 at 21:49
  • *The "Δ" doesn't even display in my IDE (Dev-C++).* Wait, how did you type that in the first place? Does your keyboard have a Delta key you can use? Did you add that character from another editor, outside of your IDE? Can you tell us more about this? – Frédéric Hamidi Oct 26 '16 at 21:50
  • 2
    @FrédéricHamidi It's likely that he copied the character from somewhere or simply added the Greek language in his keyboard settings to type it (typically it's the same key as the letter D). – Theodoros Chatzigiannakis Oct 26 '16 at 21:51
  • Does your console font support this character? – dan04 Oct 26 '16 at 22:34
  • What operating system are you using? If it's Dec-C++ on Windows it gets more complicated. – Barmak Shemirani Oct 27 '16 at 01:25
  • It might not be a useful comment, but as far as I know, Windows' console is poorly tolerant to non-ascii characters. I used to want to print Japanese characters in Python, and well, I just could not. Although, Pyzo's console (yet another Python IDE) displayed them perfectly. Long story short, maybe the console you are using just cannot do this. – Right leg Nov 25 '16 at 04:26

1 Answers1

24

If your platform supports it, you could use unicode escape characters. For Greek capital delta the code is \u0394:

#include <iostream>
int
main() {
  std::cout << "\u0394V" << '\n';
}

output: ΔV

Live Demo

For the future reader, bellow I give the escape sequences for Greek capital letters:

Letter   Description  Escape-Sequence
-------------------------------------
A        Alpha        \u0391
B        Beta         \u0392
Γ        Gamma        \u0393
Δ        Delta        \u0394
Ε        Epsilon      \u0395
Ζ        Zeta         \u0396
Η        Eta          \u0397
Θ        Theta        \u0398
Ι        Iota         \u0399
Κ        Kappa        \u039A
Λ        Lambda       \u039B
Μ        Mu           \u039C
Ν        Nu           \u039D
Ξ        Xi           \u039E
Ο        Omicron      \u039F
Π        Pi           \u03A0
Ρ        Rho          \u03A1
Σ        Sigma        \u03A3
Τ        Tau          \u03A4
Υ        Upsilon      \u03A5
Φ        Phi          \u03A6
Χ        Chi          \u03A7
Ψ        Psi          \u03A8
Ω        Omega        \u03A9

and for Greek lower letters:

Letter   Description  Escape-Sequence
-------------------------------------
α        Alpha        \u03B1
β        Beta         \u03B2
γ        Gamma        \u03B3
δ        Delta        \u03B4
ε        Epsilon      \u03B5
ζ        Zeta         \u03B6
η        Eta          \u03B7
θ        Theta        \u03B8
ι        Iota         \u03B9
κ        Kappa        \u03BA
λ        Lambda       \u03BB
μ        Mu           \u03BC
ν        Nu           \u03BD
ξ        Xi           \u03BE
ο        Omicron      \u03BF
π        Pi           \u03C0
ρ        Rho          \u03C1
σ        Sigma        \u03C3
τ        Tau          \u03C4
υ        Upsilon      \u03C5
φ        Phi          \u03C6
χ        Chi          \u03C7
ψ        Psi          \u03C8
ω        Omega        \u03C9

Live Demo

For people interested on other alphabets, as well as on other symbols, you could find more supported escape characters here.

101010
  • 41,839
  • 11
  • 94
  • 168
  • Unfortunately, @101010 , it appears the command prompt does not support the Greek Unicode escape characters. Instead of printing `Δ`, it prints `╬ö` ([here's a screenshot](https://www.dropbox.com/s/21u3qtu09qofbwj/delta.png?dl=0)). I'll try some different console applications and see if any of those works. Thanks! – Will Callender Oct 27 '16 at 22:20
  • 1
    Try what Howard proposed (i.e., "\xCE\x94V") I've tested on windows compiler and it works. Have in mind though that this stuff is not standard. – 101010 Oct 27 '16 at 23:47