c++ - Working along with digital clock -


the following program simple digital clock want time continuously synchronized system time , display on top of console without letting interfere other work in case can see "hello" on 4th last line never printed while loop above never ends , screen cleared on every loop.

i want code perform instructions outside while loop never reaches @ point because while loop never ends in program

#include <ctime> #include <iostream> #include <windows.h> using namespace std;  int main() {    bool loop = true;    while (loop)  {      time_t = time ( 0 );    tm *local = localtime ( &now );      local->tm_hour -= 6;      system("cls");     cout << ctime ( &now ) <<'\n';     cout<<"check";     sleep(1000);    }  cout<<"hello";//this not printed while loop doesnt ends   cin.get();    return 0;   } 

the reason loop isn't ending aren't ending it. set loop true @ beginning, , looping long remains true. however, never set false.

if goal create clock runs in top of command line, sort of difficult, not impossible.

essentially, you'll have use formatting library ncurses position cursor on line want print time to, clear line using clrtoeol, print time, set cursor last line. you'll have put in main loop takes user's input , sends shell interpreter, this:

std::string command; cin >> command; system(command.c_str()); 

overall, though, might easier use unix date command, this:

date "%h:%m:%s" 

every time need know time is.


Comments