i can't change the text colour!

Write your question here.

I'm trying to find a way to change the colour of the code.
It worked at the beginning with what I think was the same code, but now
it says that:

'colour' is not recognized as an internal or external command,
operable program or batch file.

***************************************************************************************************
***************************************************************************************************

***** Be cautious: The path you choose is going to decide how your adventure continues *****

***************************************************************************************************
***************************************************************************************************"

I hope someone can help me!

[code]
Put the code you need help with here.
#include "iostream"
#include "string"
#include "time.h"
#include <cstring>
#include<stdio.h>
#include<stdlib.h>

using namespace std;


int main()
{

system("colour 6");

printf(" ");
cout << endl;



string copy1 = "***************************************************************************************************";
cout << copy1 << endl;
cout << copy1 << endl << endl;
cout << "***** Be cautious: The path you choose is going to decide how your adventure contiues *****" << endl << endl;
cout << copy1 << endl;
cout << copy1 << endl;

}
Try
"color 6"
rather than
"colour 6".
Also: https://ss64.com/nt/color.html

I blame the education system!
https://howtospell.co.uk/british-american-spelling-differences
Last edited on
The color DOS command changes the color(s) of the entire display... which is typically not what people want.

You need OS-specific code. For Windows, use SetConsoleTextAttribute().

1
2
3
4
5
6
7
8
9
#include <windows.h>

void setcolors( int background, int foreground )
{
  SetConsoleTextAttribute(
    GetStdHandle( STD_OUTPUT_HANDLE ),
    (background & 0xF) << 4 | (foreground & 0xF)
  );
}

Linux (NCurses) requires some setup before you can choose colors. Let me know if you want that too.
If you are a Windows user there's a CPlusPlus article for creating a header you can include in your console programs to change foreground and background colors.

http://www.cplusplus.com/articles/Eyhv0pDG/
I do not like that article, alas.
It is something to start with, easily accessible since it is an article here.

You do kinda have a vested interest going on, with your own library.

Just sayin'.

IMO changing console colors and moving around the console window is more than a bit of a step back. Going GUI, no matter what the OS, is the 21st Century.
I suppose if I had ever posted my own library anywhere it could be claimed I have a vested interest.

My interest is more in clarity and correctness.



Maybe I will post my own library...
Topic archived. No new replies allowed.