显示用C+格式的日期+; 我尝试用cTIME在C++中的控制台中以yyyy/mm/dD格式显示当前日期,但我碰到了与它无关的数字显示,或者它什么也没显示。如何将日期分配给变量而没有任何问题?没有其他方式显示日期吗? 先谢谢你

显示用C+格式的日期+; 我尝试用cTIME在C++中的控制台中以yyyy/mm/dD格式显示当前日期,但我碰到了与它无关的数字显示,或者它什么也没显示。如何将日期分配给变量而没有任何问题?没有其他方式显示日期吗? 先谢谢你,c++,time,C++,Time,我会让你看看我做了什么 class Emprunt{ private: string datePret; string dateRendre; Adherent adherent; Livre livre; public: time_t actuel = time(0); tm *ltm = localtime(&actuel); int year = 1900 + ltm->tm_year; int month = 1 + ltm->tm_mon; int day =

我会让你看看我做了什么

class Emprunt{

private:
string datePret;
string dateRendre;
Adherent adherent;
Livre livre;

public:
time_t actuel = time(0);
tm *ltm = localtime(&actuel);
int year = 1900 + ltm->tm_year;
int month = 1 + ltm->tm_mon;
int day = ltm->tm_mday;
int hour = 1 + ltm->tm_hour;
int minute = 1 + ltm->tm_min;
int sec = 1 + ltm->tm_sec;
string date = year + "-" + month + '-' + day;

Emprunt(Adherent adh, Livre livre){
    this->datePret = date;
    this->dateRendre = "nothing";
    this->adherent = adh;
    this->livre = livre;
    livre.setLibre(0);
    adh.setNbLivreMax(adh.getNbLivreMax()-1);
}};
唯一有效的方法是在cout中显示变量month、year和date
(如下所示:
cout到一个临时
char
数组,然后分配给字符串。使用操纵器?顺便说一句,您可以通过不使用
this->
和直接访问成员来节省一些键入时间。
this->
语法只需将成员与参数区分开来,当它们具有相同的名称时。您可以通过在参数和成员之间使用不同的名称来实现这一点。