I have a program from the textbook does not start here. Will you help?

#include "stdafx.h" #include <stdio.h> #include <conio.h> 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(); } 

    2 answers 2

    First, conio.h is not part of the standard. Previously, Borland and MS supported it, but now it is disabled. Therefore, all the old examples that have this title should be corrected.

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

    If it is necessary that the console does not close immediately, then it is necessary to slightly supplement the program. This can be done, for example, by adding a call to the following function:

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

    Then the program will look something like this:

     #include "stdafx.h" #include <stdio.h> #include <iostream> #include <limits> void PressEnterToContinue() { std::cout << "Press ENTER to continue... " << flush; std::cin.ignore( std::numeric_limits <std::streamsize> ::max(), '\n' ); } int main() { float a = 5.5; float b = 1.5; float c = 3.3; printf ("BLA BLA "); PressEnterToContinue(); } 
    • one
      std::cin.ignore( std::numeric_limits <std::streamsize> ::max(), '\n' ); - oh, #cross problems ... - Athari
    • @Viktor by the way, you have a typo in textcollor - should be textcolor - Ilya

    When you pointed out that something was wrong, you would clearly write what was wrong. You do not call the doctor on the phone "I feel bad" and expect that they will help you? Not to mention the fact that it hurts, not doing tests, etc.?

    According to a specific program. It does not compile , but does not start . The unconventionality of conio.h leads to the fact that every compiler supports what it wants :), and all these functions that you are trying to use in VC ++ 2015 simply do not exist. Although conio.h itself is ...

    Or you need to rewrite the program using the Windows console API (you hardly need it ...), or take something like the good old Borland C ++ 3.1 under DOS :) and work with it.

    • Thanks I will rewrite - Viktor