问题
I am developing an Visual C++ application in windows console mode, I want to set my console text in to Bold and Italic form.
I changed console text color and background color using SetConsoleTextAttribute
function and system("COLOR XX")
functions.
But there is no Win32 API function to changed text mode in to BOLD, Italic or Stroke.
Please mention any function or mechanism to achieve it within C/C++ programming boundary in Windows environment?
回答1:
This can't be done in Windows with the standard console. Either write your own console-looking thing that does support bold/italic, etc., or use a graphical UI.
There are many ways to design a UI in Windows. If you're using C++, you can use MFC or ATL/WTL. If you're prepared to interface with .NET, you can use Windows Forms or WPF. It's been a couple of years since I did any Windows development, but you can probably write a UWP app in C++.
Consider whether you need output like this at all. You might be able to get away with generating HTML-formatted reports that people can look at in their web browser.
Or maybe you can run a local web server, and use the user's browser for your UI.
回答2:
To write in bold, you can use:
std::cout << "\e[1mbold text here\e[0m" << std::endl;
来源:https://stackoverflow.com/questions/41958156/how-to-set-c-c-console-text-in-bold-and-italic-in-windows