Funcionamiento Programa Imprime Fecha y Hora
Publicado por Daniel (1 intervención) el 23/02/2016 02:44:27
Hola, quisiera saber si pueden ayudarme a comprender el funcionamiento del siguiente programa el cual imprime la hora y Fecha del sistema. Soy principiante y lo que puedo comprender es el bucle, la pausa, el limpiar pantalla, y que utiliza una estructura e funciones básicas de entrada salida para imprimir la Fecha y Hora, pero tengo problemas al analizar la mayor parte de lo demás, principalmente la función currentDateTime() y el uso de char buf[80]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <string>
#include <time.h>
#include <cstdlib>
#include<windows.h>
// Get current date/time, format is YYYY-MM-DD.HH:mm:ss
const std::string currentDateTime() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
// Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
// for more information about date/time format
strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);
return buf;
}
int main() {
bool f = true;
while(f){ //Presionar UP
if ( GetAsyncKeyState(VK_UP)||GetAsyncKeyState(VK_RETURN)||GetAsyncKeyState(VK_ESCAPE)){
f = false;
}
else{
std::cout << "Fecha y Hora Actual=" << currentDateTime() << std::endl;
Sleep(1000);
system("CLS");
}
}
}
Valora esta pregunta


0