Sign in to follow this  
RogerThat123

C++ Console APP special Characters

Recommended Posts

I want to be able to use special characters in my console application because Im making a tic tac toe game, I need to see these chars - " ╔═══╦═══╦═══╗ ". I tried changing my IDE font to terminal like the console output font but it still didnt work. All that shows are question marks "????????????" Any ideas?

Share this post


Link to post
Share on other sites
If you're using windows, I think you can do something like:


#include <iostream>

int main()
{
std::cout << char(x); //Where x is the ASCII code of the character you want
} //end f()



Google ASCII Chart or ASCII table and you should be able to come up with a list of the ASCII character codes and the character they produce.

Share this post


Link to post
Share on other sites
To be able to display those special characters you have to type cast ints. You could make consts for each character you want displayed and then with a cout
cout << char(someInt);



I know a few IDEs that don't display the characters but the console does. And only Windows I believe, since those characters you showed are windows special characters.

This will help. It is a list of all the numbers and their corresponding character.

This is a program I made that actually uses those characters. Doing the char(int) approach was the only way I could find to get those displayed, even copying and pasting wasn't working.

Share this post


Link to post
Share on other sites
Depending on your operating system, you may be able to use system calls to display arbitrary unicode characters. For example, on Windows you should be able to do something like:

WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), L" ╔═══╦═══╦═══╗ ", 16, 0, 0);

to dump a wide character string to the console.

Share this post


Link to post
Share on other sites
You could use a stringstream assuming this is C++.

#include <sstream>

stringstream ss;
ss << char(201) << char(205) << char(205) << char(205) << char(203) << char(205) << char(205) << char(205) << char(203) << char(205) << char(205) << char(205) << char(187);
string topRow = ss.str();




Then just print out the string you want. It won't work well for part of your board because you have to fill in certain characters, but you could print the top, put in the middle containing the X's and O's, then the bottom of the first row, and so on. And I haven't looked too much into it, but with stringstream you have to find someway to either clear the stream or just make a new one with stringstream someName;. Making a new one isn't a good code practice but if you make a function that makes the row and stores it somewhere, when that function ends it will get rid of the stringstream and you can use the ss name again.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Depending on your operating system, you may be able to use system calls to display arbitrary unicode characters. For example, on Windows you should be able to do something like:

WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), L" ╔═══╦═══╦═══╗ ", 16, 0, 0);

to dump a wide character string to the console.


outputs

T%P%P%P%f%P%P%

Windows 7.

Share this post


Link to post
Share on other sites
Quote:
Original post by Dragonsoulj
You could use a stringstream assuming this is C++.

*** Source Snippet Removed ***

Then just print out the string you want. It won't work well for part of your board because you have to fill in certain characters, but you could print the top, put in the middle containing the X's and O's, then the bottom of the first row, and so on. And I haven't looked too much into it, but with stringstream you have to find someway to either clear the stream or just make a new one with stringstream someName;. Making a new one isn't a good code practice but if you make a function that makes the row and stores it somewhere, when that function ends it will get rid of the stringstream and you can use the ss name again.


This worked, thanks.

Where did you find a list of the numbers for the characters.

Share this post


Link to post
Share on other sites
If not using Unicode output functions, make sure to set the console code page before outputting anything, else your program will produce different output on different machines (or even the same machine if someone changes the code page with the chcp command-line function before running your app).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this