How to Display a Smiley Face in C++ Console - c++

When I use to have Windows 7, I use to be able to use certain codes for my C++ programs to create acsii symbols. For example, if I did "cout << (char)1;" my program would display a white smiley face in the console box. Now since I updated to Windows 10, those codes do not work anymore.
I've done research and figured out the unicode from Windows 10 has changed. In the link below, I use to be able to use symbol/code 1 through 31 but now they appear not to work on Windows 10.
Link: https://www.alt-codes.net/
My question is, is there anyway to be able to get codes 1-31 back, possibly by downloading the Windows 7 unicode or is there a new symbol to paste the smiley face from the link? And if that's the case, how would I show it from doing this: "cout << (char) ??? ";
When I use cout < (char)1, it displays displays a box with a question mark inside of it.

Related

ANSI escape code not working properly [C++]

I am using the ANSI escape code to print colored output.
I am getting proper colored output in vs code integrated terminal.
But when I am running the program in external command-prompt/Powershell, I am not getting the expected colored output.
My program looks something like this:
#define RESET "\033[0m"
#define RED "\x1B[31m"
#define GREEN "\x1B[32m"
int main(int argc, char** argv){
if(argc != 1){
std::cout << RED ">> Invalid Arguments!" RESET;
}else{
if(verify_password()){
...
...
...
}else{
std::cout << "\n>> " RED "Invalid Password!" RESET;
}
}
return 0;
}
Complete Code
NOTE: One weird thing I observed is that if I am entering the correct password then everything is working fine in both terminals(getting proper colors). But the problem is when either I am entering an incorrect password or an invalid amount of arguments
What might be the reason for this?
EDIT: I figured out a way to make it work. I find out that in order to make these escape codes work I need to have at least one call to system() function. But still, I am not sure how these things are connected.
Historically, consoles on Windows required use of the console API in the Windows SDK in order to do effects like color. But recent versions of Windows now support escape codes (and even UTF-8), but programs have to opt-in by calling SetConsoleMode with ENABLE_VIRTUAL_TERMINAL_PROCESSING. (Opting in preserves backward compatibility for older programs that aren't using escape codes or UTF-8.)
If you're getting color in some places and not others, then I'd guess there's a problem related to the state the terminal/console is in when sending the escape codes. For example, if the terminal thinks it's already processing an escape code and a new one begins, it might not recognize either. I suppose this might also be a problem if one part of the program uses escape codes but another part uses the Console API.

C++ Box drawing characters squeeze together in windows 10 console

I'm trying to print some tables in Windows console using C++.
My codes under default console settings:
cout << "╭─┬╮\n"
"├─┼┤\n"
"╰─┴╯\n";//Code I hope to work
cout << "╭ ─ ┬ ╮\n"
"├ ─ ┼ ┤\n"
"╰ ─ ┴ ╯\n";//Have an extra whitespace behind every character
gave me
The characters only take one space instead of two. They are squeezed together.
I have tried but didn't work:
Change code page to 65001(UTF-8)
Turn on and off every option except legacy mode in cmd settings hoping it would work.
Change font
I then used legacy console mode and this time it work, but for some reason I need it to work in newer mode. Can you tell me how to configure it right or is it just a bug?
OS: Windows 10 1909
Environment: CLion 2021.2.4 + MSVC v142, C++11

how to use of unicode fonts in Verifone VX675

I have a problem to write Arabic text on VeriFone vx675 pay pose model.
i trying this codes line:
int ret=set_font("Tahoma.ttf");
if (ret!=0)
{
printf("con : %d, err: %s\n",ret,strerror(errno));
}
display_at(0,0,"سلام", NO_CLEAR);
but device show an error as
Invalid Argument
could anyone say to me how i should to resolve this problem. or how i can write Unicode Arabic text in Vx675 Model.
Thanks in Advance
Disclaimer: I have not worked with the Vx675 before, nor have I tried to use an Arabic font, but I think this will work...
You can't use .ttf fonts on the VeriFone terminals. Instead, you need to use VeriFone's "Font Generation Tool" to convert a .ttf to either a .vft or .fon file.
Start "Font Generation Tool". If you installed the DTK, then it should be in your start menu under "VeriFone"
Go to the "Font" menu item and select "Convert Font".
Select "Windows Unicode Font"
Select "Arabic" as the "Custom Unicode Fonts" choice. Set whatever other styles you want.
Click through the rest of the wizard and save the font file somewhere.
Download that new font file to your terminal with the rest of your program (this is typically the step I forget to do on my first run)
When you do your "display_at" function, I'm noting that you are using the Arabic character(s) directly. I have no experience with this as to whether or not it will work, but one thing you can try if it isn't working is to use printf with numerical offsets. I don't think you'll want to do that in the long-run, but it can help you get started:
printf("%c%c%c%c%c%c%c%c", 0, 1, 2, 3, 4, 5, 6, 7);

Basic terminal output using C++ - Questions

Well, the question may sound a bit too vague but here's 2 things I need to do and I'd definitely need some input on this :
Output something (e.g. using cout) with color (note: My TERM environment variable is set to xterm-color if that makes any difference; also, is there any uniform way to output colored text that's compatible with both pure mac and *nix terminals in general, so that the code is portable)
Output something at the same position on the terminal screen. OK, this may sound confusing too. Let's take a terminal app which simply outputs a progress percentage. It normally won't start a new line for that. The new value is shown at the very same spot. How is this doable? (Being a once Borland Pascal guy from the good old DOS days, the only thing I could think of is something to do with accessing video memory directly... or not?)
So... any ideas?
You probably want to use ncurses library. And ANSI escape codes can also be used for coloring.
1)
You can try Color cout , but that is not protable. I tried (ANSI escape codes) something like
cout << "\033[1;31mbold red text\033[0m\n";
cout << "\33[0;31m" << "Enter Your String here" << "\33[0m" << std::endl ;
You can also look at
How do I output coloured text to a Linux terminal?
2)
Are you looking for something like watch or top like app which are showing output at the same spot.

Superscript in C++ console output

I'd like to have my program output "cm2" (cm squared).
How do make a superscript 2?
As Zan said, it depends what character encoding your standard output supports. If it supports Unicode , you can use the encoding for ²(U+00B2). If it supports the same Unicode encoding for source files and standard output, you can just embed it in the file. For example, my GNU/Linux system uses UTF-8 for both, so this works fine:
#include <iostream>
int main()
{
std::cout << "cm²" << std::endl;
}
This is not something C++ can do on its own.
You would need to use a specific feature of your console system.
I am not aware of any consoles or terminals that implement super-script. I might be wrong though.
I was trying to accomplish this task for the purpose of making a quadratic equation solver. Writing ax² inside a cout << by holding ALT while typing 253 displayed properly in the source code only, BUT NOT in the console. When running the program, it appeared as a light colored rectangle instead of a superscript 2.
A simple solution to this seems to be casting the integer 253 as a char, like this... (char)253.
Because our professor discourages us from using 'magic numbers', I declared it as a constant variable... const int superScriptTwo = 253; //ascii value of super script two.
Then, where I wanted the superscript 2 to appear in the console, I cast my variable as a char like this...
cout << "f(x) = ax" << (char)superScriptTwo << " + bx + c"; and it displayed perfectly.
Perhaps it's even easier just to create it as a char to begin with, and not worry about casting it. This code will also print a super script 2 to the console when compiled and run in VS2013 on my Lenovo running Windows 7...
char ssTwo = 253;
cout << ssTwo << endl;
I hope someone will find this useful. This is my first post, ever, so I do apologize in advance if I accidentally violated any Stack Overflow protocols for answering a question posted 5+ years ago. Any such occurrence was not intentional.
Yes, I agree with Zan.
Basic C++ does not have any inbuilt functionality to print superscripts or subscripts. You need to use any additional UI library.
std::cout << cm\x00B2;
writes cm^2.
For super scripting or sub scripting you need to use ascii value of the letter or number.
Eg: Super scripting 2 for x² we need to get the ascii value of super script of 2 (search in google for that) ie - 253. For typing ascii character you have to do alt + 253 here, you can write a any number, but its 253 in this case.
Eg:-cout<<"x²";
So, now it should display x² on the black screen.
Why don't you try ASCII?
Declare a character and give it an ASCII value of 253 and then print the character.
So your code should go like this;
char ch = 253;
cout<<"cm"<<ch;
This will definitely print cm2.