• Advertisement
Sign in to follow this  

console app-c++

This topic is 4724 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way of clearing all the writing in the console app? thnks

Share this post


Link to post
Share on other sites
Advertisement
Ugh. All these ugly hacks.

The console is not a "screen", it is just an output stream. If you would like to treat it (or something which looks the same, at least) as a screen (where you can reference particular locations, clear everything visible, etc. and not have the window scroll as you continuously append text), then get an appropriate library. [google] 'curses' or 'ncurses' for a start.

Share this post


Link to post
Share on other sites
after writing the fanciest console snake ever i tried to deal with this too. there is no way but system("cls"). Back buffering and playing with the width height will help the jitteryness if your going for real time console app with graphics

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
No it isn't.

std::system is in

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
All of those wont work if you call your app like this:
app.exe > lpt1

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement