2

is it possible to format the console output, like writing in bold, of a C/C++ program? I'm talking just about the console output (so no high-level) e.g.:

std::cout << "\b this is bold";
std::cout << " this is not";

I hope there are some libraries, this program is intended for Linux.

Thanks for advises.

user3085931
  • 1,757
  • 4
  • 29
  • 55
  • 1
    @AlexandruCimpanu, That's not console output. – chris Jun 20 '14 at 06:06
  • I looked at the accepted answer after I red the question: _There is no concept of bold text in C++, there may be in a particular device that displays character text, for example rich-text-format or HTML tagging or a terminal screen. The latter usually involves sending some "escape sequence" relevant to that particular terminal._ – Alexandru Cimpanu Jun 20 '14 at 06:08
  • 3
    It depends on your terminal/console: the most widely used escape codes are probably those used by [ANSI](http://en.wikipedia.org/wiki/ANSI_escape_code), vt100/220, xterm et al: "\033[1m bold \033[0m not bold". – Tony Delroy Jun 20 '14 at 06:09
  • Well I remember terminal programs (like in DOS) that are capable to write in bold. Is this because of C/C++ or is there the trick done with Bash/Batch ? – user3085931 Jun 20 '14 at 06:10
  • See http://en.wikipedia.org/wiki/ANSI_escape_code – laune Jun 20 '14 at 06:11
  • thanks @TonyD that's what I'm looking for. On which systems is this working? – user3085931 Jun 20 '14 at 06:12
  • @T.C. it's not necessary to pick one - the question is ultimately about the terminal and pretty much language agnostic; whether the code's `std::cout << "..."` or `printf("...")` isn't a big deal. – Tony Delroy Jun 20 '14 at 06:13
  • The terminal emulation programs interpret ANSI escape sequences, accordng to the type of terminal they emulate. Some DEC terminals used to be very popular, VT 100,... – laune Jun 20 '14 at 06:14
  • @user3085931: pretty much every terminal/console program that's capable of displaying bold text... some printers might expect you to backspace and print twice to get "bold" output. If you're using linux/unix, `echo` implementations vary a little bit but you could try `echo -e "\033[1m bold \033[m not bold"` to test it. – Tony Delroy Jun 20 '14 at 06:18
  • @TonyD well there has to be some kind of criteria: I tried in the Eclipse console it's not working but when I call the program from the linux terminal it's alright. – user3085931 Jun 20 '14 at 06:20
  • @chris: Here you go, I found one duplicate for console output with the answer using VT100 sequences. – Matthieu M. Jun 20 '14 at 06:26
  • 1
    @user3085931: "has to be some kind of criteria" - if you want some ability to detect whether it's supported, I suggest you use ncurses - it utilises a "database" tracking what features are available in thousands of terminals. – Tony Delroy Jun 20 '14 at 06:29

1 Answers1

0

That is not a question about C or C++ but rather about your particular console. Any answer is specific to your target, and possibly in Linux dependent the specific particular terminal emulator.

In most cases a terminal, terminal emulation, or in case of Windows a console window, there will be no support for bold as such - you can often control the colour and brightness of a fixed font however. You can do this in a number of ways - again platform specific - for example through a library such as curses, by sending terminal specific escape sequences, or in Windows through the Win32 Console API.

Without knowing the specific platform, it is not possible to give a specific answer, and even then that answer may not be portable to other platforms.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • thank you for the answer. In the Top post I said it is intended for a C/C++ program in a console on a linux machine. – user3085931 Jun 20 '14 at 06:21
  • @user3085931 : so you did. It is always a good idea to establish the environment early in a question - not everyone will read to the bottom! ;-) In this case it is the most important factor more important that the language. – Clifford Jun 20 '14 at 10:49