C++: How to change the size of text and change text properties (i.e. bold and italics)

Steph 61 Reputation points
2021-12-05T05:40:02.647+00:00

I would really like to change the size of the text that is output by the program and even maybe change it to being bold, but I have no idea where to even start. Just as an example...

Say I wanted this program to make the output bold instead of plain, and to make the font size 36, what should I add?

#include <iostream>

using namespace std;

int main()
{
     cout << "This text is bold, like me.\n";
     return 0;
}
Developer technologies C++
Developer technologies Small BASIC
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,521 Reputation points
    2021-12-05T10:20:53.977+00:00

    You can use Console APIs, like :

    #include <iostream>    
    #include <Windows.h>
    
    using namespace std;
    
    int main()
    {
        static CONSOLE_FONT_INFOEX  fontex;
        fontex.cbSize = sizeof(CONSOLE_FONT_INFOEX);
        HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
        GetCurrentConsoleFontEx(hOut, 0, &fontex);
        fontex.FontWeight = 700;
        fontex.dwFontSize.X = 36;
        fontex.dwFontSize.Y = 36;
        SetCurrentConsoleFontEx(hOut, NULL, &fontex);
        cout << "This text is bold, like me.\n";
      return 0;
    }
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.