How to give to a variable in input hours and minutes in c++ using <ctime>?

35 views Asked by At
#include <iostream>
#include <ctime>
#include <string>
#include <sstream>
#include <iomanip>
#include <cctype>

int main() {

    time_t now = time(0);
    tm* ltm = localtime(&now);
    int day = ltm -> tm_mday, month = ltm -> tm_mon +1 ,year = ltm -> tm_year + 1900, min = ltm -> tm_min , hour = ltm ->tm_hour;
    std::cout << "Insert hour and mins (hh:min)"<<endl;
    std::cin >> datafat;
    std::stringstream (datafat) >> get_time(&aggt,"%hh:%mm");
    int hourg = aggt.tm_hour, ming = aggt.tm_min ;
    std::cout << min << " " << ming << '\n';
    std::cout << hour << " " << hourg << '\n';

    return 0;
}

So when comparing the two moments (std::cout << min << " " << ming << '\n'; std::cout << hour << " " << hourg << '\n';) the ming and hourg come up as 0 and not like in the input.

0

There are 0 answers