win32 Overwriting current line in cmd prompt

This is a discussion on win32 Overwriting current line in cmd prompt within the C++ Programming forums, part of the General Programming Boards category; Hey guys Im creating a win32 program that runs in a DOS box (cmd prompt style) and I am hoping ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,672
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 05:04 AM
  3. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 03:53 PM
  4. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 05:21 PM
  5. Replies: 4
    Last Post: 11-14-2001, 09:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21