I'm trying to write a program that outputs the cent symbol (¢) in Visual Studios 2010 and when I copy and paste the symbol into my text it outputs a completely different symbol. I've also tried using \u00A2 and I still get a different wacky symbol. What is the C++ source code for the sign?

Recommended Answers

All 4 Replies

To see every available character, compile and run this code, if you can make the "cent" symbol in a char or string, it'll be there:

#include <iostream>
#include <iomanip>

using namespace std;

int main()
 char c;
 for (int x = 0; x <= 255; x++ )
  c = char(x);
  cout << setw(3) << x << " = " <<setw(1) << c << " ";
  if ((x % 8 == 0)&&(x > 1))
   cout << "\n";
 return 0;

This depends on how your console/terminal interprets the character code. Every character is represented by a number. The mapping between number and character depends on which character encoding is being used. \u00A2 is a ascii representation of the unicode code point 0x00A2 representing the cent symbol. Since unicode requires one or more bytes to represent one code point (number) these bytes also need to be encoded, normally with UTF-8, UTF-16 or UTF-32. Besides unicode there are a lot of other character encoding schemes like Windows-1252 or ISO-8859-1..

So it all depends on 'who' is presenting the characters and what character encoding this application uses. Normally your application's output is connected to a terminal or console application. So you have to know what character encoding your console is using.

The extended ASCII character encoding scheme has the cent symbol represented by the decimal number 162, which is A2 in base 16. The reason this is the same number as the unicode code point is because unicode is compatible with ASCII.

So what is the source code for the cent symbol??

The code that you used is correct in some sense. Whether the character that is displayed on the screen when you run the program is not a matter of how the program is written or how it is compiled. It is a matter of which environment you are running the program in. In your case, the program runs in a console (a.k.a. terminal or command prompt). These consoles use one type of encoding to translate the characters that are written from their binary (numerical) code to an actual character displayed. So, with that code you have, it would correctly be displayed if your console used an ascii unicode format, I guess it doesn't. Either try to change the coding to ascii unicode (via an option of your console window) or use the program that Red Goose posted to display all the characters and their corresponding numerical value. If either fails (i.e. you can't change it to ascii unicode, and you cannot find the cent symbol), you can try to use wide characters instead (16bit in length). For this, you will have to figure out what encoding your console is using by looking it up on the internet, find the code for the cent character in that encoding, and then use wchar_t instead of char in your code.

Be a part of the DaniWeb community

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