【发布时间】:2017-02-27 06:29:54
【问题描述】:
我一直试图在 C++ 中获取当前日期一段时间,但我无法弄清楚我做错了什么。我查看了几个站点,并且我实施的所有解决方案都收到一条错误消息:“此函数或变量可能不安全。考虑改用 localtime_s。”我尝试了找到here 的几个解决方案(包括下面的一个),但我无法让它们中的任何一个工作。我做错了什么?
#include <iostream>
#include <iomanip>
#include <string>
#include <ctime>
using namespace std;
int main()
{
const int SALARY = 18;
const int COMMISSION = .08;
const int BONUS = .03;
int monthlySales;
int appointmentNumber;
time_t t = time(0); // get time now
struct tm * now = localtime(&t);
string name;
//this is where the user adds their name and date
cout << "Please enter the sales representative's name: ";
cin >> name;
cout << "Please enter the number of appointments: ";
cin >> appointmentNumber;
cout << "Please enter the amount of sales for the month: $";
cin >> monthlySales;
//clear screen and execute code
system("cls");
cout << setfill(' ');
cout << "Sales Representative:" << name << endl;
cout << "Pay Date:" << (now->tm_mon + 1) << " " << now->tm_mday << " " << (now->tm_year + 1900) << endl;
cout << "Work Count:" << appointmentNumber << "Sale Amount"
<< monthlySales << endl;
system("pause");
return 0;
}
【问题讨论】:
标签: c++