I have an labaratoly work from my university - I have to print ASCII table with ukrainian symbols, then make transliteration from ukrainian to english but I have met problems.
So, I am to print ASCII
extended table in C++
, it must include Ukrainian letters (cyrilics).
I am on KDE neon 5.26
linux distribution, it is based on Ubuntu
. Terminal is KDE's Console
obiviously.
I made that code:
#include<iostream>
int main(void) {
for (unsigned char i = 32; int(i) < 255; i++) {
std::cout <<" [" << i << "] " << int(i) << " \t";
if ((i-1)%5 == 0)
std::cout << "\n";
}
char ua_str[] = "Привіт"; // hello in ukrainian
std::cout << "\n\n" << ua_str << "\n" << ua_str[4] << " is " << int(ua_str[4]) << "\n";
return std::cout.fail() ? EXIT_FAILURE : EXIT_SUCCESS;
}
Compiled it with g++ lab3.cpp
. It produces such output:
I am interested, how it printed char ua_str[]
but won't print ua_str[4]
.
Terminal encoding is set to UTF8
, I cannot find ASCII
in Terminal encoding settings. If I redirect output to abc.txt
text file with ./a.out > abc.txt
and open it, it looks like the next:
So, I ran locale -a
in terminal:
Then I ried to add std::setlocale(LC_ALL, "uk_UA.utf8");
to my program in int main(void)
before the for
loop but It didn't changed anything, output is the same...
I am to make transliteration script later but can't print and work properly with ukrainian letters...
So, question is: How to print and work with cyrillic cahrs in C++
on KDE neon 5.26
?
I think than I have tried everething I could and it wont work. Please help me.
This is a rtf for Ukrainian Character Set KOI8-U : https://www.rfc-editor.org/rfc/rfc2319.html .... You can map your std ascii table to the required cyrillic characters. Another option is to look at something like yandex. https://yandex.com/dev/translate/ it is an api for translating but I think its a service that charges but there is usage limits or just a temporary key if not paid for. It's pretty useful for translating and an easy api.