Home > Software engineering >  How do i solve the include path error in vs code?
How do i solve the include path error in vs code?

Time:10-30

I am using macOS Big Sur. First I got include path error for #include <stdio.h>. I don't remember/know how it got resolved and now I'm getting error for #include <conio.h> but not for <stdio.h>.

This is my code :

#include <stdio.h>
#include <conio.h>
int main() {
int a;
int b;
scanf("%d%d", &a , &b) ;
printf("%d",a);
return 0;
}

Compiler output:

fatal error: 'conio.h' file not found
#include <conio.h>
         ^~~~~~~~~
1 error generated.
 

I've tried configuring the compiler path, but the error is still not resolved.

CodePudding user response:

<conio.h> is a MS-DOS header file and Turbo C (TCC) is obsolete. Stop using it. The codes written on TCC are not compatible on most modern C compilers.so, dont use <conio.h> header file

#include <stdio.h>

int main() {
int a;
int b;
scanf("%d%d", &a , &b) ;
printf("%d",a);
return 0;
}

CodePudding user response:

Let's see what Wikipedia says:

<conio.h> "is a C header file, used mostly by MS-DOS compilers. It is not part of the C standard library or ISO C, nor it is defined from POSIT

So, because Mac is not based on MS-DOS, the library isn't C standard, and there's no maintaining for compatibility between operating systems, your machine will not know what <conio.h> is. You should use the standard <stdio.h> in C or <iostream> in C .

using standard C <stdio.h> (printf() and scanf())

#include <stdio.h>
int main() 
{
    int a;
    int b;

    scanf("%d%d", &a , &b);
    printf("%d%d", a , b);

    return 0;
}

Using standard C <iostream> (using std::cin and std::cout)

#include <iostream>
// using namespace std; is bad

int main()
{
    int a{};
    int b{};

    std::cin >> a >> b;
    std::cout << a << b;

    return 0;
}

CodePudding user response:

There are various ways to solve your problem. Let me give you the basic solution. Hover over the #include <stdio.h> for few seconds, you will get the yellow bulb. Left click it then click on Edit 'includepath' settings. Then add your compiler path.

If you can't do above thing, then best method will be uninstall gcc completely, then reinstall it. Then it will work.

If you still can't solve the problem , do contact me.

  •  Tags:  
  • c c
  • Related