1 #include <iostream>
2 #include <cstdio>
3 using namespace Std;
Ten class clock{
One public:
Clock (time_t t = 0)
13 {
tm*local = LocalTime (&t);
M_h = t? local-> tm_hour:0;
m_m = local-> tm_min;
m_s = local-> tm_sec;
Setbuf (Stdout,null);
19}
void run (void)
21 {
for (;;)
23 {
Show ();
Tick ();
26}
27}
Private:
void Show (void)
30 {
To printf ("\r%02d:%02d:%02d", m_h,m_m,m_s);
32}
tick void (void)
34 {
Sleep (1);
(++m_s = 60) {
Panax Notoginseng m_s = 0;
if (++m_m = = 60) {
m_m = 0;
if (++m_h = 24) {
M_h = 0;
42}
43}
44}
45}
M_h int;
m_m int;
m_s int;
49};
int main (void)
51 {
Clock Clock (Time (NULL));
//clock Clock
//clock.hello;
Clock.run ();
0;
57}
Clock1.cpp: in member function ' void Clock::tick () ':
Clock1.cpp:35:13: Error: ' Sleep ' has not been declared in this scope
Function Name: Sleep function: Perform suspend for a period of time usage: unsigned (unsigned milliseconds); Use with the top file in VC #include <windows.h> in the GCC compiler, The header file used differs from the GCC version #include <unistd.h>
The first English character in sleep in VC is the upper-case of "S" in standard C, which is sleep, not uppercase. Use uppercase to illustrate the following, Exactly what you use to see the compiler. Simple to say VC with sleep, the rest of the use of sleep. The general form of the sleep function: sleep (unsigned long), where the unit in sleep () is in milliseconds, so if you want the function to stay for 1 seconds, it should be sleep (1000); Under Linux, Sleep's "s" Do not capitalize the units in sleep () in seconds, not milliseconds. In the kernel, the realization of sleep is realized by both the pause function and the alarm function.