Hi gays (i'm Artur from Italy), can someone of you help me? I started to study a C++, but i have some question, how can i color a single word for exemple i have a program that verify a passwd, i want to write (Access denien (in italian Accesso negato) using red color)?
//Passwd
#include <iostream>
#include <windows.h>
using std::cin;
using std::cout;
using std::endl;
int main()
{
system("COLOR 0A");
int pass;
int Counter=0;
for(Counter=0; Counter<3; Counter--)
{
cout<<"Inserisci la PASSWORD di sicurezza (solo cifre da 0 a 9)...:\n"<<endl;
cin>>pass;
for(int x=0; x<5; x++)
{
cout << "\nControllo PASSWORD in corso...";
_sleep(100);
Beep(2500, 100);
}
if (pass!=12345)
{
cout<<"\a\n\nAccesso negato...\n"<<endl;
}
elsebreak;
}
cout<<"\a\n\nAccesso concesso...\n"<<endl;
int scelta;
cout<<"1) PASSWORD di sicurezza massima:\n"<<endl;
cin>>scelta;
if (scelta==1) cout<<"PASSWORD di sicurezza massima: 12345\n"<<endl;
else cout<<"\a\nPuoi inserire solo il numero 1...\n\a"<<endl;
system("pause");
return 0;
}
Changing the color is not implemented in C++. You have to use an external library or system call to change color of the console window. A library such as ncurses could handle that, but since you are already using system... and I also see that you are using the pause command... I am going to assume you are at a microsoft dos command prompt of some sort. Color changing in this situation can be done using system to execute the dos color command.
Thanks for answer, the problem is this way color all my text, i want to color a single word (example: ACCESS DENIED) in red and (ACCESS GRANTED) in green, only this words ;)
And yes, i start learning c++ two weeks ago, on a windows OS.
Another question, as you can see, in my "program" which i copied and modifyed a bit, a password is 0-9 how can i change it to A-Z?
And, when i insert my passwd, then i chose 1, the program ask to press any button and it close, how can i do to restart a program without re-open it again? Here is some code i think?
Thanks for your help :D