How to display real time in c++

前端 未结 6 925
梦如初夏
梦如初夏 2021-01-24 14:04

Can some one tell me how do i display real time in c++. what i mean is that while the program is running you can see the seconds and or minutes counting down like a real clock h

6条回答
  •  孤城傲影
    2021-01-24 14:30

    Try this:

    while (true) {
        std::cout << '\r'; // return to the beginning of the line
        getAndPrintTime(); // do what you do now, but don't write endl
    }
    

    Assuming that you want to keep overwriting the same place in the terminal, two simple things to use are '\r' for carriage return, and '\b' for backspace (if you want to back up a character rather than a whole line).

提交回复
热议问题