看了一段代码,根据版本的编译日期生成版本号,觉得很不错,记下来以后可用,哈哈
GetVersion() { std::string monthes[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", }; std::string dateStr = __DATE__; int year = atoi(dateStr.substr(dateStr.length() - 4).c_str()); int month = 0; for(int i = 0; i < 12; i++) { if(dateStr.find(monthes[i]) != string::npos) { month = i + 1; break; } } std::string dayStr = dateStr.substr(4, 2); int day = atoi(dayStr.c_str()); std::string timeStr = __TIME__; std::string hourStr = timeStr.substr(0, 2); int hour = atoi(hourStr.c_str()); char version[20]; sprintf(version, "1.0.%04d%02d%02d%02d", year, month, day, hour); return version; }
时间: 2024-11-06 19:15:15