Reputation: 412
I want to print extended ascii characters in console, I tried this:
std::cout << "╔══════════╦════════════════════════════════════════════════════════╗\n";
std::cout << "║ ID:678 ║ Name: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ Surname: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ Gender: ▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ Age: ▓▓▓ ║\n";
std::cout << "║ ║ Tel: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ Adress: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ID Print ║ Hobbies: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ║ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ░░░░░░ ║ Additional İnformations: ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ▒▓▓▓▓▒ ║ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "║ ▓▓▓▓▓▓ ║ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ║\n";
std::cout << "╚══════════╩════════════════════════════════════════════════════════╝\n";
but output is like this:
?????????????????????????????????????????????????????????????????????
? ID:678 ? Name: ???????????????????????????????????????? ?
? ? Surname: ???????????????????????????????????????? ?
? ? Gender: ?????? ?
? ? Age: ??? ?
? ? Tel: ??????????????????????????????? ?
? ? Adress: ????????????????????????????????????????? ?
? ? ????????????????????????????????????????????????? ?
? ID Print ? Hobbies: ???????????????????????????????????????? ?
? ? ????????????????????????????????????????????????? ?
? ?????? ? Additional ¦nformations: ???????????????????????? ?
? ?????? ? ????????????????????????????????????????????????? ?
? ?????? ? ????????????????????????????????????????????????? ?
?????????????????????????????????????????????????????????????????????
But when i try this: std::cout << char(200);
it successfully print '╔' character. so i'm sure Console supports extended ascii characters.
So; how can i output these cout's correctly?
Edit: using std::wcout << L"";
isn't working.
Edit2: Program will only run in Windows 7 or later.
Edit3:
Using this code prints card out,
#include <fcntl.h>
#include <io.h>
_setmode(_fileno(stdout), _O_U16TEXT);
But then, I can't print any normal cout characters, it gives error.
(example error string: std::cout << "Hello!"
)
Upvotes: 3
Views: 754
Reputation: 412
For guys who wrote on windows, can apply this: source(_setmode Windows source)
Needed Libraries:
#include <fcntl.h>
#include <io.h>
To transform cout to Unicode:
_setmode(_fileno(stdout), _O_U16TEXT);
*Important Note: in this style, you always supposed to be use std::wcout << L""; for this. if your code includes std::cout in other lines, here is the solution:
use _setmode(_fileno(stdout), _O_TEXT);
to set stdout back to default text style, when you don't need special characters to print.
Upvotes: 1