How to set C/C++ console text in bold and italic in Windows?

纵然是瞬间 提交于 2020-01-24 00:52:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!