I would like to say hello, first of all.
I have been attempting to change the color of a character on my program for some time now.
The characters in question will represent lava tiles with the letter "L" in my program.
I would like to know how I can change individual character color in a Console program without having the change affecting all the characters.
Any ideas?
(The platform in question is windows console.)

You can switch the console text color at will quite easily. Just change it to the desired color before printing the character, then change it back after printing the character:

#include <iostream>
#include <windows.h>

class TextAttr {
    friend std::ostream& operator<<(std::ostream& out, TextAttr attr)
    {
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), attr.value);
        return out;
    }
public:
    explicit TextAttr(WORD attributes): value(attributes) {}
private:
    WORD value;
};

#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)

int main()
{
    std::cout << "Regular text\n"
              << TextAttr(FOREGROUND_INTENSITY | FOREGROUND_GREEN)
              << "Bright green text\n"
              << TextAttr(FOREGROUND_WHITE)
              << "Back to regular\n";
}

Sorry but There is only Blue, Red, and Green for the color of the Back/Fore-ground?

Edited 1 Year Ago by Maxime_2: Ortograph

This question has already been answered. Start a new discussion instead.