Garunas, you need to be much much much more descriptive in your questions.
Do you want to change the background color of the console, of a win32 window, of a windows forms app, of a opengl window, of a <insert library here> window, of a picture, of your desktop, of your screen saver.... i could go on.
There is nothing in the iostream library that will change the color of your consule window which I'm only pointing out because it was the only one you included in your sample code.
In my defence the OP did specify a console window, and was not including any of the MS libraries in his sample code. I never advocated calling system() or anything like that, I left the method to pass the argument completely up to the OP.
Letting the OS do it for you implies that.
And even if you don't make a call to system(), if you let the OS do it for you, it makes your program platform dependent. You should always try to make your programs able to run on more than Windows, its good practice.
A very simple thing to do is to use system("color 01");
Change the 01 with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
00 = Black
01 = Blue
02 = Green
03 = Aqua
04 = Red
05 = Purple
06 = Yellow
07 = White
08 = Gray
09 = Light Blue
0A = Light Green
0B = Light Aqua
0C = Light Red
0D = Light Purple
0E = Light Yellow
0F = Bright White
This will change all the text in the console into what you choose.
Now from what i read about the command system(); many people say it is wrong from different reasons..one thing i can tell you sure about system("color 01") is that is a bit slow.but it works for fun :)
Since I know that Mihay07 isn't going to read a 7 page thread I'll sum it up for him. The people on this site who do the most to help others, the go-to-guys as it were, have a thing against using the system() function for several reasons that they explain rather well. This has bled it's way into the culture of this site and will see that you are persecuted and burned as a heretic for suggesting it especially to new users. The only time it seems to be exceptable is when the system() call is a small part of the program and is being used to prototype a solution until the real problem is addressed.
You phrase that rather brutally. No one's getting "persecuted and burned", rather they are being redirected to a thread explaining why calls to system() shouldn't be made, nothing rude involved. People aren't labeled as "noobs" (or other unfriendly terms) just because they recommend using the system() function. They were simply taught a correct (but inefficient, and terribly heavy) way to handle the problem at hand. This isn't their fault, and if it takes redirecting every new person to that same thread to improve peoples code, then so be it.
Well " Computergeek01 " to be honest with you i read something about system() from different links i found and i found in one topic something weary interesting about it.not just stopping the console closing or changing colors.
"when you directly execute a program, it gets the same privileges as your program -- meaning that if, for example, you are running as system administrator then the malicious program you just inadvertently executed is also running as system administrator. If that doesn't scare you silly, check your pulse.
It doesn't matter if you aren't sysadmin either. Anything you can do it can do."