Hello ,
I want to print accented character to console. There are 4 examples.
It's only the 3th example works.
The 4th doesnt but it has differents issues.
pls let me know if it isn't clear. Thanks
Code:
// Console char set code
#include "pch.h"
#include <iostream>
#include <iterator>
#include "windows.h"
UINT myCharSetCode;
using namespace std;
int main()
{
struct poetry {
string author;
string title;
string text;
wchar_t text_wchar_t;
};
poetry proemio;
poetry *p;
p = &proemio;
p->author = "Omero";
p->title = "Odissea";
p->text = "Narrami, o musa , l'uomo dall'agile mente che a lungo andó vagando, ";
myCharSetCode = GetConsoleCP(); //it's 437
/*
https://en.wikipedia.org/wiki/Code_page_437
*/
/******************************************************************************************/
/* Example n°1*/
cout << "This is the " << myCharSetCode << " char set code." << endl;
cout << "\x85 = 133 but cout cant prints à" << endl; // that is it prints α
cout << "\xA0 = 160 but cout cant prints á" << endl; // that is it prints ß
cout << "\x8A = 138 but cout cant prints è" << endl; // i didnt find
cout << "\x82 = 130 but cout cant prints é" << endl; // that is it prints Θ
/******************************************************************************************/
/* Example n°2*/
for (char c : p->text){ // another example
cout << c; // Here, cout prints wrong char. It cant print 'ó'
}
/*****************************************************************************************/
/* Example n°3*/
/* a working example */
setlocale(LC_ALL, ".437");
wcout << L"\n àé éè \n";
/***************************************************************************************************/
/* Example n°4*/
/* Trying to print wchar_t of the struct */
setlocale(LC_ALL, ".437");
p->text_wchar_t = "àèéó"; // cant assign, error. It's an error
//wcout << ......
}
Code:
/* Example n°4*/
/* Trying to print wchar_t of the struct */
setlocale(LC_ALL, ".437");
p->text_wchar_t = "àèéó"; // cant assign, error. It's an error
//wcout << ......
1) How Do I assign a string to wchar_t which is part of a struct ?
2) Is this the 3th example the 'official way' to print to console or I'm making it harder?
3) I'm reading about char code , because I dont know it,
but I've another question.
If I have the same code on console (437) and I need that code set to print my chars ,
Why Don't the first and second example work ?
I didnt used SetConsoleOuput because that code is what I need