0

I want to print each letter in different colors in C++. For example, 6 letters. These are first letter light blue, second letter light green, third letter light cyan, fourth letter light red, fifth letter light magenta, sixth letter yellow.

I found other codes online. But these completely change all the letters in the console. For example, all text is just red. What I want is for each letter to be in a different color and the system, namely the return text, to remain in its own color.

  • Then you'll probably have to change the color prior to printing each of the characters. – digito_evo Dec 11 '21 at 07:03
  • I'm looking for exactly what you said. My guess is that I'm going to create an empty string of letters, change the color of each letter individually and insert it into that string of letters. Then I will print this array. But I couldn't find any code like this. The code shapes I always find change the console completely. For example, all letters are red. – shirley Dec 11 '21 at 07:12
  • C++ does not support that. What I mean is that you can use a `std::map` to store the characters as the value and their colors as the key. Then you can iterate through the map using a range-based for loop and retrieve each `char` and its color and then change the console foreground color and then print the `char`. For example, if you have 50 chars then you'll need to change the terminal foreground color 50 times. – digito_evo Dec 11 '21 at 07:17
  • I guess I'm not at this level yet. I could not fully understand. Can you write a little short code? Associated with it. Especially map here. – shirley Dec 11 '21 at 07:44
  • Actually you should not use a map in this case. You better use vector and I have written a solution based on that for Windows but you'll have to ask another question cause it won't fit in here. Also, which OS do you use? – digito_evo Dec 11 '21 at 08:08
  • I am using Windows 10 Home. Do I need to create a question again in the same way? I don't understand why it doesn't fit right here. I just started using this site. – shirley Dec 11 '21 at 08:28
  • Great. The solution works on Windows. And yes ask another one since your current question was closed. – digito_evo Dec 11 '21 at 08:31
  • 1
    https://stackoverflow.com/questions/70313706/c-change-the-color-windows-10-home – shirley Dec 11 '21 at 08:37

0 Answers0