How might someone be able to color a specific line if text?
I already know about system("color 4A"); but I want only a specific line to be colored a color.
By the way, MERRY CHRISTMAS!
#include <windows.h>
#include <iostream>
//Think about wrapping WinAPI calls to throw exceptions
//instead of constant erorcode checking
int main()
{
// Get handle to STDOUT.
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdout == INVALID_HANDLE_VALUE)
return EXIT_FAILURE;
// Save the current text colors.
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))
return EXIT_FAILURE;
WORD wOldColorAttrs = csbiInfo.wAttributes;
// Set the text attributes to draw red text on black background.
if (! SetConsoleTextAttribute(hStdout, FOREGROUND_RED | FOREGROUND_INTENSITY))
return EXIT_FAILURE;
std::cout << "HI\n";
// Set the text attributes to draw green text on black background.
if (! SetConsoleTextAttribute(hStdout, FOREGROUND_GREEN | FOREGROUND_INTENSITY))
return EXIT_FAILURE;
std::cout << "Hi again!\n";
// Restore the original text colors.
SetConsoleTextAttribute(hStdout, wOldColorAttrs);
}
EDIT: Windows only. For *nix based OS, lookup documentation on its API
Attribute Meaning
FOREGROUND_BLUE Text color contains blue.
FOREGROUND_GREEN Text color contains green.
FOREGROUND_RED Text color contains red.
FOREGROUND_INTENSITY Text color is intensified.
BACKGROUND_BLUE Background color contains blue.
BACKGROUND_GREEN Background color contains green.
BACKGROUND_RED Background color contains red.
BACKGROUND_INTENSITY Background color is intensified.
COMMON_LVB_LEADING_BYTE Leading byte.
COMMON_LVB_TRAILING_BYTE Trailing byte.
COMMON_LVB_GRID_HORIZONTAL Top horizontal.
COMMON_LVB_GRID_LVERTICAL Left vertical.
COMMON_LVB_GRID_RVERTICAL Right vertical.
COMMON_LVB_REVERSE_VIDEO Reverse foreground and background attributes.
COMMON_LVB_UNDERSCORE Underscore.
You could try red and green? Just mix and match until you get what you want. Try using loops to get every possible choice.
You will want to mix and match these
1 2 3 4 5 6 7 8
FOREGROUND_BLUE Text color contains blue.
FOREGROUND_GREEN Text color contains green.
FOREGROUND_RED Text color contains red.
FOREGROUND_INTENSITY Text color is intensified.
BACKGROUND_BLUE Background color contains blue.
BACKGROUND_GREEN Background color contains green.
BACKGROUND_RED Background color contains red.
BACKGROUND_INTENSITY Background color is intensified.
Which means there are 8! possibilities
By the way you should just use SFML :P or even MS Paint