我有以下代码:如何时间转换为整数
#include <ctime>
#include <stdio.h>
#include <iostream>
#include <chrono>
using namespace std;
const std::string currentDateTime() {
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%X", &tstruct);
return buf;
}
int main() {
std::cout << "Current Time is: " << currentDateTime() << std::endl;
return 0;
}
我编译此,我也得到:当前时间为:十八点30分11秒
我想知道如何转换那成一个整数,所以它只出现在18.5或者这些线上。我想这样做,因为我想创建一个时间表。
例如:如果10点半,我希望程序能够告诉我,我有什么主题(学校)。 类似这样的:
if(time == 10.5)
std::cout<<(subject);
有关如何做到这一点的任何建议?我对C++相当陌生,而且我不确定我是否会以完全错误的方式去解决这个问题。有没有另一种方法来做到这一点? 在此先感谢。
'18.5'不是一个整数。 – 2014-08-28 08:40:06