Skip to content

codes to display a smiley and sad face in C++ console

An answer to this question on Stack Overflow.

Question

i'm a newbie in C++, i need a help to get a smiley and sad face using c++ console, below was the code i got but it was not giving me big smiley face and sad face too.

i would appreciate it if any one can assist.

thanks.

#include<iostream.h>
using namespace std;
int main()
{
    
      printf("%C",2);
      std::cin.ignore();
}

Answer

Depending on your terminal, these characters may correspond to ASCII codes 1 and 2, which otherwise denote the Start of Header (SOH) and Start of Text (STX) control characters.

You could test this by trying:

#include <stdio.h>
int main(){
	printf("\1 \2");
}

Alternatively, you could use unicode's emoticons block in conjunction with wchar, a suitable locale, and a suitable font to access a wide variety of smiley faces.