Conio.h无法在codeblocks中工作(未定义的引用…)

我正在使用Code :: Blocks,事情是我多次尝试修复Conio库以及其他一些库的问题。 每次我使用clrscr();类的东西clrscr(); textcolor(); 或任何它说的;

  Undefined reference to textcolor. 

例如,这个简单的程序应该以特定的颜色显示总和但是虽然我之前已经看过它但它没有用完。

 #include  #include  int fx(int x,int y,int z) { return x+y+z; } int main() { int a,b,c; printf("Enter three values to a, b and c.\n"); scanf("%d%d%d",&a,&b,&c); int total=fx(a,b,c); textcolor(14); printf("Output ="); cprintf(" %d",&total); getch(); return 0; } 

PS:我正在使用GNU GCC。 有时候当我选择另一个编译器或者只是打开Code :: Blocks时,它会说“有些插件缺失”,或类似的东西。 谁能帮忙?

gcc不支持conio.h .

gcc不支持conio.h . 这是conio.h的实现。

gcc不支持conio.h . 您可以尝试curses库,它支持创建文本用户界面 。 有许多curses,你可以使用带有代码块的ncurses或pdcurses库。

原始Borland conio.h中的一些function很容易复制 – 我最近从Turbo-C程序(从1990年开始!)移植到gcc,并找到了我能用的getch和getche(用于Linux)的版本在线使用(但不是C ++版本,不能使用gcc命令编译)。 我编写了自己的cgets版本,但还没有发现需要从该头文件创建自己的其他函数版本。

 char getch() { char c; // This function should return the keystroke without allowing it to echo on screen system("stty raw"); // Raw input - wait for only a single keystroke system("stty -echo"); // Echo off c = getchar(); system("stty cooked"); // Cooked input - reset system("stty echo"); // Echo on - Reset return c; } char getche() { char c; // This function should return the keystroke, with echo to screen system ("stty raw"); // Raw input - wait for only a single keystroke c = getchar(); system ("stty cooked"); // Cooked input - reset return c; } char *cgets(char *buf) /* gets a string from console and stores it in *buf; buf[0] must be initialized to maximum string size and *buf must be declared by caller to maximum string size plus 3 bytes, to accommodate string, terminating null, size byte in buf[0] and length of entered string in buf[1]; sets buf[1] to length of string entered and returns pointer to buf[2] */ { /* declare and initialize internal variables */ unsigned int count = 2; /* start at 2 because [0] is max size including terminator and [1] returns actual */ /* entry size, also including terminating null */ char input = '\0'; /* initialize to null */ /* start actual function */ while (count < buf[0] + 2) /* while within permitted string length -- +2 for size control bytes */ { input=getch(); /* get a single character, without echo */ if (input != (char) 13) /* not cr/enter key -- presumed meaningful input */ { printf("%c",input); buf[count++] = input; /* store character and increment counter */ } else { buf[count] = '\0'; /* change cr/enter key to terminating null */ buf[1]=(char) count - 2;/* store length of entered string (including terminating null) */ count = buf[0] + 2; /* terminate entry loop -- +2 for size control again */ } } return &buf[2]; /* return pointer to start of string */ } 

要记住的关键是包含的文件(例如conio.h)不必预编译; 如果它只是更多的C源代码,它可以同样有用。