One of my students was asked to write a game "snake" on the first (!) Course. In order to clearly explain to her how to write this, I decided to write it myself first and in the course of the action I encountered the following problem.
They work with Visual Studio. To develop a program that draws something in the console, you need a console clearing function (to redraw the playing field printed with pseudographic characters), a console positioning function (to redraw not the entire playing field, but its necessary area) and the key processing function Arrows to move the snake.
All these functions are in Borland C ++ Builder (also with coloring the console to the heap), but in Visual Studio there is only the last one ( getch ), and this is non-standard. To clear the console, you need to write system("cls") (as I understand it, cls is a Windows shell command, which is not a fact that it will work in other OSs), but in order to implement the gotoxy analogue, you generally need to connect Windows.h and call WinAPI functions. But when I do this, my program stops compiling when the Disable language extensions compiler option is on. Microsoft themselves write that this option is needed to ensure cross-platform. And here I wondered if it was possible to write a cross-platform program with a similar interface at all, since it turns out that it cannot be done without using any C ++ extensions to Microsoft or Microsoft. Indeed, in the C ++ reference book it is clearly stated that the standard library in principle does not allow processing the input of a single character without Enter.
I tried to google, as with this in cross-platform Java, and I got the impression that it was impossible to write such a program in Java. By the way, even if you don’t try to do something old-school, like graphics in the console, in windows with cross-platform is also not so good: for example, here: The tray icon in Java . In addition, I came across the fact that one program written in QT (also of the cross-platform type) worked only if the visual styles of Windows were turned off for it in the program compatibility wizard, otherwise a narrow strip was displayed on the screen instead of a window.
The only solution that comes to my mind is to take the header file conio.h in the borland version, where everything you need is there, and implement it yourself in a separate *.c file, and the implementation of this file will be different for different platforms. Actually, something like this I did. Perhaps other users know the solution better.
putchar('\f'), as well as'\r'and'\b', but I do not guarantee anything. I think your version with a separate conio.h implementation for each system is the best. - Qwertiy ♦getchin VS2005 is definitely buggy. More precisely, he seemed to be working, but when he was combined with scanf, some kind of jambs appeared. - Qwertiy ♦