Store an Ascii char in an array in c++ - c++

first of all thanks for reading ^ ^
ok, so I'm making an easy menu for a console project
after I created the options I wanted to add the char(240) as another option but I can't figure out how to declare it I cant just write ≡ because Dev++ won't let me write it, the code is:
char *menu_list[6] = { " SYMBOL GOES HERE "," View ", " Edit ", " Search ", " Reset", " Quit " };
does anyone know how to do this? or if I'm doin it all wrong, can you tell me the right way to do it?
i'm forced to make it work on windows, i can
cout << char(240);
and it works right, but I cannot store that same symbol into menu_list
also I got the code from here
http://www.theasciicode.com.ar/extended-ascii-code/hyphen-ascii-code-240.html

There was a deleted answer that had the correct response: use "\xf0" to represent the character.
Ordinarily you would need to know which code page is being used by Windows to know how a character code maps to a particular character on screen. However by doing the research yourself, you already know that the decimal value 240 represents the character you need. That decimal 240 is the same as hex f0, and the way to embed a hex literal value in a string is to prefix it with \x.
As noted in the link you posted, these codes correspond to code page 437. This is the one used by the command window in English versions of Windows; I'm not sure if alternate language versions of Windows use anything different. Calling this "extended ASCII" is confusing, since there have been many attempts to extend ASCII over the years and none of them are the same.

Related

How to append a long to a string in C++?

I'm working on a school project and I'm making a VEX Robotics program. It's in C++, and I am very new to this language. I can't import any new libraries to help me and I want to display a value on a screen. Unfortunately, I need to make it say "Left Stick tilt: " and then the tilt value of the VEX controller's left stick and the same with the right stick. The code should work aside from the fact that I can't simply add the two together and have the value of the controller tilt converted to numerical characters. Here's my code:
Controller1.Screen.setCursor(1, 1);
Controller1.Screen.print("Left Stick tilt: " + Controller1.Axis3.position());
Controller1.Screen.setCursor(2, 1);
Controller1.Screen.print("Right Stick tilt: " + Controller1.Axis2.position());
Could anyone experienced with the VEX system help me? (I'm using VEXcode V5 on a chromebook, if it makes any difference)
Edit: so far everyone has recommended things within libraries. I was not clear enough; I cannot use any libraries, including the standard library, due to the limitations of VEXcode V5
How to append a long to a string in C++?
In order to append long to a string, you must convert the integer to a string. You can for example use std::to_string.
You can append to another string like this:
long l = 42;
std::string s = "look at this long: ";
s += std::to_string(l);
Alternatively, you can use a format string. For example:
std::string s = std::format("look at this long: {}", l);
However, for purposes of output, don't necessarily need to append to the string. Instead, you could keep them separate, output the string, and then output the long.

printing multiplication sign in c++

In Qt for setting the label of a button to be the "Multiplication sign" (not astrisk(*)) this is used :
Button *myButton = new Button("\303\227");
I don't know anything about "\303\227". Also the code below will not print "Multiplication sign" :
cout << "\303\227" ;
I could not search for it cause I had no "keywords".
I need some keywords and some information about this number and why cannot it be printed with cout object.
Also i didn't want to add Qt tag for this question cause I think this is not much Qt related.
Thanks in advance.
those are called octal codes for UTF-8 characters, and I believe C++ has no useful native Unicode support. However, you may refer to this question
for how to use unicode in qt.
if you just want the multiplication symbol you may use this “×” U+00D7 or this U+2715 ✕

printing string with c++ for language other than english

Hi I am trying to print a string in c++, which is not in English, and the output is always ????, for example, I want to print a korean world '선배' or Thai word 'ยิ่ง', the simple code snippet is as follows-
main(){
string name("선배");// string name("ยิ่ง");
int len=name.size();
cout<<"\n name: "<<name;
cout<<"\n length "<<len;
}
OUTPUT:
name: ??
length 2
Where as if I change the string line by English character as-
string name("ab");
OUTPUT:
name: ab
length 2
Update: I also tried wchar_t, which is also printing question marks.
code-
wchar_t *a=L"อดีตรักงานไหม";
wprintf(L"sss : %s \n" , a);
I checked the property of the project, project properties->configuration properties->general and the Character set is set as ' Use Unicode Charecter Set'
Anybody can please tell me what is going wrong? How can I get it printing different languages?
regards
I'm not familiar with korean, but in general you need to do two things:
Set the correct code page using std::locale OR use unicode (for example std::wstring and std::wcout).
Set your console to a font that can display those characters. The default font in Windows can not do this.
If you are using Windows, you can set the console font by using SetCurrentConsoleFontEx
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof cfi;
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = 16;
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
wcscpy_s(cfi.FaceName, L"Consolas");
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
IF you want to set it independent of your actual application or you do not have the prerequisites for the function above, you can have a look at the different guides on the internet, for example this one.
I have no clue what font may support asian characters, you will need to check this yourself. Any unicode font should do.
You need to write byte order mark (BOM) first then you can print this.
I am working on a project in Hebrew using Microsoft Visual Studio Community 2019.
When trying to output string literals of non-English characters in any way, I get either question marks in boxes, or just question marks. I checked to see how the command line handles the situation by saving a file with a Hebrew name in Explorer and then accessing it through CMD. Again, question marks.
I am guessing there is a way to include the language packs in the c++ script (that's what I am looking up now), but saw this and wanted to share what else I found out. By looking at the Disassembly of my code I noticed that the Assembler is mishandling the assignment to the register. When the value (characters) are loaded, the Unicode formatting (right to left) causes the Assembler to flip the parenthesis and shift the first two (last two) values to the opposite side resulting in an unusable value in the register:
eax,dword ptr [ב (0BDF3A0h)]
Eeven as I try to save this it comes out wrong: what it should be is a zero, a right-parenthesis, a space, and then the Hebrewcharacter enter image description here
which should be [(0בBDF3A0h)].
(Somehow in my code, I now have the Unicode for א outputting the value assigned to it...)
I'm looking at how to handle the issue. Hopefully, you know more than I do :-) Good luck!
More:
As variable
as string literal

(Homework) Easiest way to format a table-like list and a logic issue?

So, my teacher gave us a document for an assignment due this Tuesday. Unfortunately its not very clear. I have a strong grasp of the basics of programming, but not with C++. Here are my questions.
1.) Right now I clear the screen with system("cls"), and I print the menu screen with spaces and \n for formatting. The doc says to look up something called stdlib.h and a clrscr() function and how it can be used for clearing lines i.e. clrscr(4).....
I found nothing on google, do you guys know what he's talking about?
2.) What is the easiest way to format a table-like list in C++? Example of what I am trying to achieve here:
The way it outputs each line is in 3 different cout's, first one with t: x and the 1st number, second one tacking on the 2nd number to the right, and third one tacking on the last number and endl. This will then loop until some parameter is met.
3.) Is my logic above sound? The problem is, I do not understand the assignment doc he provided, and my e-mails remain unanswered. So I've tried to just do it as intuitively as I can and thats what I came up with. Here is the snippet from the doc that I don't get:
I know its kind of an intricate issue I'm having so if you would like some more context for the last screenshot please let me know.
Any help is appreciated, thanks!
1.) Right now I clear the screen with system("cls"), and I print the menu screen with spaces and \n for formatting. The doc says to look up something called stdlib.h and a clrscr() function and how it can be used for clearing lines i.e. clrscr(4).....
try using cplusplus.com, it is awesome and will answer a lot of your questions.
http://www.cplusplus.com/reference/cstdlib/?kw=stdlib.h
2.) What is the easiest way to format a table-like list in C++?
Well personally, I think using the following function:
setw()
would be the best way to go about making a chart like that.
I feel this is better than just doing "\t" or " ",
because it will do work more efficiently, and in a organized manner.
Let's put setw() and "\t" to the test:
Let's say we have values 8 and 10,000 and want to print the values.
cout << "\t" << "8";
cout << "\t" << "10000";
will output:
8
10000
while if you had:
cout << setw(8) << "8";
cout << setw(8) << "10000";
it would output:
8
10000
It's just an issue of keeping your code organized and looking nice.

Visual studio not executing code correctly

Yeah so ive tried lots of stuff but the output keeps coming out all messed up. Heres a picture showing whats going on. As you see the letter variable gets all weird.
The problem is that "letter: " + letter" doesn't do what you think it does, it adds the integral value of letter to the const char* string literal "letter". Easiest fix is string("letter: ") + letter.