Is there a way to format the text in a basic console program? By formatting I mean like changing the colour of text or maybe underlining it?
If yes, how?
As far as I am aware if you are creating non OS-dependant code then I don't think there is a way to underline text in the basic console without the user of some GUI API.
Went though the post. Didn't understand any of the code given there. And it states nothing about underlining.
I really would appreciate an explanation regarding the code.
Well in that forum thread they present two methods of changing colours. The first method is a windows dependant
system("Color 1A");
method which changes the current colour of the console output to '1A'.
The other method is non-OS dependant code which is a bit more complicated. What it does is that it created an array of bit colour codes 'colours[]' of which it iterates through changing the colour for every "Hello World" output until the user press any key. He changes the colour by using this function:
SetConsoleTextAttribute( hstdout, colors[ index ] );
To answer your lack on input about underlining in the post, please reread what my original response was:
As far as I am aware if you are creating non OS-dependant code then I don't think there is a way to underline text in the basic console without the use of some GUI API.
What I want to know about the first form of code, the system dependent one.Since I am only making programs for the sake of learning and don't intend to use it in any more than as a hobby or a pass-time, it shouldn't be any problem. I will have to understand a lot more about coding before I understand the other method.
So how can I decide the color of the text (that is, what colour does 1A mean, or if I want to use any other colour, how can I change it to the code format)?
@ GodPyro: The second method, the one provided by Duoas, IS OS dependent. The "SetConsoleTextAttribute(...)" function is part of the Win32 API not STL, if you look again his second line of sample code is to include windows.h.
Honestly I don't see the problem with using "system(...)" in this context. None of the arguments against it are applicable to this case since the "color" is a command and not a seperate program.
As for a cross platform method to underline characters, you would have to change the character map for that environment and have a compatible character map to begin with. I haven't seen anything to suggest that the current STL supports this. The third party libs fake it by using precompiler checks to test the environment and set global macros so the other parts know which functions to use, just open the header files and it's pretty easy to see that's what their doing.
To find out which colours you are using i.e. "1A" I did a quick search and couldn't find a resource online displaying a table of the colour codes. The quickest solution would be to fool around a bit in your code and see what the bit translations are.
@ GodPyro: Must have been a darn quick search, Nah just kidding I have this resource bookmarked: http://ss64.com/nt/color.html
Save that site, it comes in handy when working with Windows outside of C++.
@ OP: Sorry when I said "Character Map" I should have said Font Set. But that almost doesn't matter since again I've seen nothing to suggest that STL supports doing this.
@Nisheeth, can I ask why you want to know this? Is this in the scope of a programming project?
I was trying out what I had learnt so far by making a Quiz. I was using a couple of famous quotes in the questions which I wanted to highlight to make them look separate from the question. I wanted to use it there
And thanks a lot Computergeek01.
Now once again, is there a way to emphasize text or underline it apart from changing colour (bold, italics etc)?
@ OP: Now once again, NO there is not. You need to use a third party library. If you pick one that I know I may be able to help you from there. But I will not write the code for you.