Home c++ Why didn't conio.h connect?

Why didn’t conio.h connect?

Author

Date

Category

My program from the textbook does not start here. Will you help?

# include "stdafx.h"
#include & lt; stdio.h & gt;
#include & lt; conio.h & gt;
using namespace std;
int main ()
{
  float a = 5.5;
  float b = 1.5;
  float c = 3.3;
  textbackground (BLUE);
  textcollor (RED);
  clrscr ();
  cprintf ("BLA BLA");
  _getch ();
}

Answer 1, authority 100%

First, conio.h is not part of the standard. Borland and MS used to support it, but this is now disabled. Therefore, all the old examples that have this heading need to be corrected.

I suggest the following: remove the lines #include & lt; conio.h & gt; and _getch (); from the program. And replace cprintf with printf . There is also no easy way to set the color, so let’s remove the textbackground and textcolor for now. After that, she must earn. If that’s enough, then good.

If you want the console not to close immediately, then you need to slightly supplement the program. This can be done, for example, by adding a call to the following function:

# include & lt; iostream & gt;
#include & lt; limits & gt;
void PressEnterToContinue ()
{
 std :: cout & lt; & lt; "Press ENTER to continue ..." & lt; & lt; flush;
 std :: cin.ignore (std :: numeric_limits & lt; std :: streamsize & gt; :: max (), '\ n');
}

Then the program will look something like this:

# include "stdafx.h"
#include & lt; stdio.h & gt;
#include & lt; iostream & gt;
#include & lt; limits & gt;
void PressEnterToContinue ()
{
 std :: cout & lt; & lt; "Press ENTER to continue ..." & lt; & lt; flush;
std :: cin.ignore (std :: numeric_limits & lt; std :: streamsize & gt; :: max (), '\ n');
}
int main ()
{
 float a = 5.5;
 float b = 1.5;
 float c = 3.3;
 printf ("BLA BLA");
 PressEnterToContinue ();
}

Answer 2, authority 67%

When you indicate that something is wrong, you would clearly write what is wrong. You do not call the doctor on the phone “I feel bad” and expect that they will help you? Not to mention what exactly hurts, without doing tests, etc.?

For a specific program. It won’t compile and not won’t run .
The non-standard nature of conio.h causes each compiler to support what it wants 🙂 and all those functions you are trying to use are simply not available in VC++ 2015. Although conio.h itself is …

The program either needs to be rewritten using the Windows console API (you hardly need it …), or you need to take something like the good old Borland C++ 3.1 under DOS 🙂 and work with it.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions