Let me phrase it like that - to say that a console is a less than ideal environment for game development would be somewhat of an understatement. This was an understatement.
At least use ncurses or something like that - that will give you the functionality you need (and more) without binding you to windows.
The thing is, because C++ doesn't have the concept of "outputting to a console" - only "put stuff into a stream" - things like "clear the console window" aren't there by default in C++ (stdout might be a file stream, or a stream that sends output to a printer etc). So you'd have to use third party libraries (like you're using the WinAPI function SetConsoleCursorPosition for your gotoxy). So if you wanted to do console stuff that already requires third party libraries, ncurses is the logical conclusion.
Huh? No, there's at least one ncurses implementation for windows on gnuwin32's sourceforge page. Allegro isn't meant for consoles either, it's a library for low level gaming routines (like graphics, sound, input etc).
// Clearing The Screen.cpp : main project file.
#include <stdafx.h> // Used with MS Visual C++ Express. Leave off if using different compiler
#include <stdio.h>
#include "conio.h"
#include <iostream>
#include <windows.h>
usingnamespace std;
void cls( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 }; // home for the cursor
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
// Get the number of character cells in the current buffer.
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
{
return;
}
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
// Fill the entire screen with blanks.
if( !FillConsoleOutputCharacter( hConsole, // Handle to console screen buffer
(TCHAR) ' ', // Character to write to the buffer
dwConSize, // Number of cells to write
coordScreen, // Coordinates of first cell
&cCharsWritten ))// Receive number of characters written
{
return;
}
// Get the current text attribute.
if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
{
return;
}
// Set the buffer's attributes accordingly.
if( !FillConsoleOutputAttribute( hConsole, // Handle to console screen buffer
csbi.wAttributes, // Character attributes to use
dwConSize, // Number of cells to set attribute
coordScreen, // Coordinates of first cell
&cCharsWritten )) // Receive number of characters written
{
return;
}
// Put the cursor at its home coordinates.
SetConsoleCursorPosition( hConsole, coordScreen );
}
void Pause()
/* Wait for a return key to continue */
{
char YN;
cout << "\n\n\t\t<--- Please press 'Enter' to continue... --->";
while ( (YN = getchar() ) != '\n') ; /* Just wait for Enter key */
return;
} /* End of Pause() */
int main( void )
{
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
for (int y = 0;y<1520;y++)
printf( "X" );
Pause();
cls(console);
cout << "\n\n\t\t";
return 0;
}