This is a simple C++ program that continuously displays the current local time in HH:MM:SS format. The time updates every second, clearing the console screen before each update.
- Fetches the current system time.
- Displays the time in real-time with automatic updates.
- Clears the console before each update for a clean display.
- A C++ compiler (e.g.,
g++). - A Unix-like operating system (Linux/macOS) or Windows with a compatible terminal.
- Open a terminal and navigate to the directory containing the source file.
- Compile the program using:
g++ -o clock clock.cpp
- Run the program:
./clock
- Open a terminal and navigate to the source file location.
- Compile the program:
g++ -o clock.exe clock.cpp
- Run the program:
clock.exe
- The program enters an infinite loop.
- It retrieves the current system time using
time(0)andlocaltime(). - It clears the console using
�[H�[J(ANSI escape sequence). - The formatted time is printed in
HH:MM:SSformat. - The program waits for 1 second using
sleep(1), then repeats.
- The program uses
�[H�[Jto clear the console, which works in Unix-like terminals. On Windows, usesystem("cls")instead. - To stop the program, press
Ctrl + C.
This project is open-source and available under the MIT License.