I'm learning C++ and I cannot figure out how how to print special characters in C++. Even when I've seen others post related to this issue, any of them solves this:
I just want to print out this chars -> '♦', '♥', '♣', '♠';
And when I do this ->
std::cout << '♦' << std::endl;
It prints out a number such as 14850470, but when I pass the char to a function, such as ->
char foo(char a)
{
return a;
}
int main()
{
std::cout << foo('♦') << std::endl;
}
It prints out 'ª' instead, any ideas?
(I'm writing this in VSCode with the MSVC compiler on Windows.)
EDIT:
The answers solved my problem (I executed chcp 65001
on the CL). But I have to change this std::cout << '♠' << std::endl;
to this std::cout << "♠" << std::endl;
in order to work, since printing as char prints nothing on the console.