如何解决VS Code中macOS Big Sur系统下的头文件路径错误(conio.h未找到)
Hey there! Let's work through this conio.h error you're hitting. Here's what you need to know:
Why you're seeing this error: The
conio.hheader file is a Windows-specific library that's not included in Unix-like operating systems like macOS. It was originally used for console input/output functions (likegetch()orclrscr()) that aren't part of standard C, so macOS's compiler (clang/gcc) has no idea where to find it.Quick fix for your current code: Looking at your code, you aren't actually using any functions from
conio.h—your program only relies onstdio.hfunctions (scanf()andprintf()). So the simplest solution is to just delete the line#include <conio.h>entirely.Your cleaned-up code will look like this:
#include <stdio.h> int main() { int a; int b; scanf("%d%d", &a , &b) ; printf("%d",a); return 0; }Verify it works: Compile again with your usual command (e.g.,
gcc yourfile.c -o output), and you should no longer get the error. Run the executable with./outputto test it.
If you ever need functionality that conio.h provided (like reading a key press without waiting for Enter), you'll need to use macOS-specific alternatives (like the termios.h header for terminal control), but that's not necessary for your current program.
内容的提问来源于stack exchange,提问作者Khushi Bharti

