Re: Clearing the screen - Press any key...

From: Ulrich Eckhardt (doomster_at_knuut.de)
Date: 09/01/04


Date: Wed, 01 Sep 2004 07:09:13 +0200

Steve wrote:
> //Sample code for pressing any key to continue...
> char anykey;
> cout << "Press any key to continue...";
> cin >> anykey;
> cout <<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
> //End sample
>
> So that code requires that you actually enter some character before
> pressing enter. How do you make it so that you can simply press the
> space bar and press enter to clear the screen?

std::cout << "<enter>" << std::flush;
std::string str;
std::getline( std::cin, str);

> Also is there a better way to clear the screen other than using
> \n\n\n\n\n\n\n\n\n\n (the method for clearning the screen must be an
> ANSI/ISO Standard C++ command/code).

No, there isn't.

For text-based, menu driven programs, you should take a look at one of the
curses libraries. They feature much more, e.g. tracking single keypresses
and positioning the cursor and are available for a wide range of
platforms.

Uli

-- 
FAQ: http://ma.rtij.nl/acllc-c++.FAQ.html


Relevant Pages

  • Re: Reading a string of unknown size
    ... replace above with int main ... '2 * sizeof *str'. ... failed to check the return value of mallocabove for failure. ... You've overwritten your earlier nul character. ...
    (comp.lang.c)
  • Re: Reading a string of unknown size
    ... replace above with int main ... '2 * sizeof *str'. ... failed to check the return value of mallocabove for failure. ... You've overwritten your earlier nul character. ...
    (comp.lang.c)
  • Re: 3 Str Dwarf Wizard
    ... I rolled my first ever character with a natural 3 -- that's right, ... Since your Str is already 3, ... Spell Focuses for conjuration and/or enchantment, ...
    (rec.games.frp.dnd)
  • Re: Novice Ranger
    ... This character looks like a challenge character. ... the hardest race of all, with both bad Hit Dice, and CON penalty. ... Get more STR and DEX ... > - Ring of Accuracy ...
    (rec.games.roguelike.angband)
  • Re: 3 Str Dwarf Wizard
    ... manipulate, and arm a crossbow. ... If you're really wanting to play the character with that low of Str, ... Making a powerful and interesting spell build ...
    (rec.games.frp.dnd)