How can I color a particular word in the console?
- Is it really impossible to select a word in the console, whether it is color or otherwise? - Vladislav Solopov
- Within the language - no way. The standard C ++ library does not support console management, only output in TTY mode. Use system-dependent methods. For example, WinAPI. - VladD
- @VladD Here is the complete task: "By pressing an arbitrary key, in turn, selects each word of the text, contains the minimum number of characters." Is it really so difficult labatatorku? We didn’t learn any events, didn’t learn how to win - Vladislav Solopov
- You do not ask us, but the one who gave the task. Maybe he meant a specific compiler and a specific non-standard library, how do we know? - VladD
- oneAnd this, which is typical, is also not supported in pure C ++, but only by system-specific libraries. : - \ - VladD
|
2 answers
If you use cout:
#include <Windows.h> #include <WinCon.h> HANDLE hStdout, hStdin; hStdin = GetStdHandle(STD_INPUT_HANDLE); hStdout = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hStdout, FOREGROUND_RED | FOREGROUND_INTENSITY); cout << "text" << endl; |
If the compiler is Borland C ++ 3.1, then the getch , gotoxy and cprintf functions will help. All of conio.h.
|