Thread: Returning to previous line

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    15

    Returning to previous line

    Hello, is there any way to output a string to previous line with std::cout ?
    The output would look like:


    Line which I wrote second
    Line which I wrote first



    or, alternately any function, that clears the whole console screen?
    Last edited by Garland; 08-08-2007 at 06:18 AM. Reason: Wrong tag

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Cheap and dirty way include cstdlib (I think), and use:

    system("cls");

    Alternatively read the faq

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    It is not possible with std::cout I think. "cls" clears the screen.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    Registered User
    Join Date
    Aug 2007
    Posts
    15

    the creator in learning

    Ok, thank you both, though I think throwing the monitor out of windows is one of the fastest and most reliable solutions, as they say.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You can send all sorts of ANSI escape-codes to the console window under Windows - it may not be as easy as doing "system("cls");", but it's more efficient and you can do more things than just clear the screen (such as move the cursor or erase to end of line and so on)

    See: http://en.wikipedia.org/wiki/ANSI_escape_code

    --
    Mats

  6. #6
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Generally if you are writing a program that is supposed to have full controll over console, you should use OS APIs, you can use #ifdefs to make your program portable. With std::cout you can go forward, but can't come back. It is like posting a letter. You can post as many letters as you want to any destination, but you can't bring them back at any time you want!
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  7. #7
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Two options I can think of.

    1) Use Win32 API console routines to set the cursor position and do other stuff (anything with the console you can do)

    2) Use linux ncurses (or a windows port of the library) and do the same thing.

    One is portable, one is not. If yer on a windows box of course you wont have to install ncurses library to use the API just read up on MSDN.

  8. #8
    Registered User
    Join Date
    Aug 2007
    Posts
    15
    Thanks all for your time and help, although by now, you must have probably forgotten, that you even provided it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 07:58 AM
  2. Imposing Line Numbers automatically in the C code
    By cavestine in forum C Programming
    Replies: 14
    Last Post: 10-15-2007, 12:41 AM
  3. Trouble replacing line of file
    By Rpog in forum C Programming
    Replies: 4
    Last Post: 04-19-2004, 10:22 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM