首页 > 解决方案 > 如何更改控制台上的特定线条颜色?使用最新的 IDE 在 C 中编码时。如果我使用系统(“颜色”)而不是整个前景色变化

问题描述

 This code is used to select menu options using the up & down arrow 
key but I want the output line in the arrowhere function as coloured
and output lines in menu function should be different in colour
on Console as compared to the line of function arrowhere
      void menu()
            {
                system("cls");
                int position = 1;
                int keypress = 0;
                while (keypress != 13) Counter Char Key Enter Is Set
                {
                    system("cls");
                    arrowhere(1, position);
                    printf("Addition\n"); Its color will be remain default such that white
                    arrowhere(2, position);
                    printf("Subtraction\n"); Its color will be remain default such that white
        
                    arrowhere(3, position);
                    printf("Exit\n"); Its color will be remain default such that white
        
                    keypress = getch();
                    if (keypress == 80 && position != MAX) To check down key 
                    {
                        position++;
                    }
                    else if (keypress == 72 && position != MIN)To Check Upper Key
                    {
                        position--;
                    }
                    else
                    {
                        position = position;If any other key except Enter is pressed than position is not affected
                    }
                }
            }

void arrowhere(int realposition, int arrowposition) 输出与菜单功能中存在的列表相邻的箭头位置。

        {
            if (realposition == arrowposition)
            {

printf("--->> - "); 我只想将这条线的颜色更改为蓝色,这个箭头出现在菜单选项旁边,请参见 Menu() 函数。}

        }

标签: c++c

解决方案


推荐阅读