Thread: win32 Overwriting current line in cmd prompt

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    2

    win32 Overwriting current line in cmd prompt

    Hey guys Im creating a win32 program that runs in a DOS box (cmd prompt style) and I am hoping to implement a function that will basically wait for a certain time and out put it to the window.....

    Trouble is, I have the time thing sorted but when I output to the screen like this:

    cout << timeElapsed;

    It will just keep writing it over and over and over again .....

    12 27 39 47 59 66 78 89 99 103 etc etc

    I want it to output the current time elapsed but I want it to overwrite the previous value without making a new line .... can anyone tell em how to do that please?

    So it want it to look like this....


    MY TIMER:
    Time elapsed: 12

    then

    MY TIMER:
    Time elapsed: 27

    etc etc


    I DONT want it to write on new lines so I don't want to use endl; cos it looks messy.....

    Does anyone know how to achieve this?

    Thanks for your help.
    aniceguyuk

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Like
    Code:
    cout << "Time elapsed:" << myTime << '\r' << flush;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    2
    Quote Originally Posted by Salem View Post
    Like
    Code:
    cout << "Time elapsed:" << myTime << '\r' << flush;
    You're a legend mate .... I've been programming for 4-5 years and I ain't ever come across this ....

    I really appreciate it.

    Thanks
    aniceguyuk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 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
  2. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM
  3. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM
  4. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM
  5. Replies: 4
    Last Post: 11-14-2001, 10:28 AM