I'm building a dictionary, and when I print(output) the word-defenitions I'd like to print the word itself in bold. when I print
cout<<word<<endl<<defention1<<defenition2<<endl;
I want the only "word" to be bold.
How can I do that?
Standard C++ uses various locales/character sets to display the output in various alphabets. However, the text itself is just that, text, without formatting.
If you want your output to be
colored
, orbold
, oritalicized
, then you need to send an appropriate character code to your terminal.
However, this is implementation-defined and not guaranteed to work on all platforms.
For example, in Linux/UNIX you may use ANSI escape codes if your terminal supports them.
Example that works on my Mac OS X:
#include <iostream>
int main()
{
std::cout << "\e[1mBold\e[0m non-bold" << std::endl; // displays Bold in bold
}
If you want, you can go an extra step and create manipulators for turning on/off the bold-ing:
#include <iostream>
std::ostream& bold_on(std::ostream& os)
{
return os << "\e[1m";
}
std::ostream& bold_off(std::ostream& os)
{
return os << "\e[0m";
}
int main()
{
std::cout << bold_on << "bold" << bold_off << " non-bold" << std::endl;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With