console app-c++

Started by
16 comments, last by Trap 19 years, 1 month ago
If you use windows and want a fast function to clear the screen, try this code.

void clrscr(){	cout.flush();	static HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);	COORD coord = {0, 0};		DWORD dw;		CONSOLE_SCREEN_BUFFER_INFO csbi;	DWORD dwSize;	GetConsoleScreenBufferInfo(hConsole,&csbi);	dwSize = csbi.dwSize.X * csbi.dwSize.Y;	FillConsoleOutputCharacter(hConsole,								' ',								dwSize,								coord,								&dw);	FillConsoleOutputAttribute(hConsole,								csbi.wAttributes,								dwSize,								coord,								&dw);	SetConsoleCursorPosition(hConsole, coord);}
WyrmSlayer RPG - In Early Development
Advertisement
This maybe no use at all but...

#define WIN32#ifdef WIN32         system("cls");#else         system("clear");#endif


Should work for windows or unix, for unix simply comment out the define statement, i think it's in the std namespace, haven't used it for a while but should get the job done in a simple manner.
Although Radagar's method looks far more intelligent (and complex for a simple app).
"The FFT - an algorithm the whole family can use" ... and for my next joke...
#include <iostream>
using namespace std;

int main()
{
system("pause");
}

it works, before you tell me I am wrong, compile it.
Quote:Original post by game mercenary
#include <iostream>
using namespace std;

int main()
{
system("pause");
}

it works, before you tell me I am wrong, compile it.


system()

Also, iostream->istream->ostream->ios->xlocnum->cstdlib->stdlib.h
Quote:_CRTIMP int __cdecl system(const char *);

in VC++7.1, which is why it is 'working'. It is not, however, in iostream. It is in stdlib.h.

Regards,
jflanglois
Just use

#define CLRSCRN {for (int i=1;i<=200;++i) cout << "\n";}

Then use CLRSCRN in the code.
Gary.Goodbye, and thanks for all the fish.
Quote:Original post by game mercenary
#include <iostream>
using namespace std;

int main()
{
system("pause");
}

it works, before you tell me I am wrong, compile it.


[grin]
-----------------------------Play Stompy's Revenge! Now!
Quote:Original post by garyfletcher
Just use

#define CLRSCRN {for (int i=1;i<=200;++i) cout << "\n";}

Then use CLRSCRN in the code.


This works, but sometimes it causes flicker.
-----------------------------Play Stompy's Revenge! Now!
All of those wont work if you call your app like this:
app.exe > lpt1

This topic is closed to new replies.

Advertisement