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 | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Developer technologies | Small BASIC
Developer technologies | Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Castorix31 91,506 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.