温馨提示×

c++年月日输出代码如何写

c++
小亿
330
2023-11-10 13:54:13
栏目: 编程语言

要输出C++中的年月日,可以使用std::cout语句来输出。以下是一个简单的示例代码:

#include <iostream>

int main() {
   int year = 2022;
   int month = 1;
   int day = 1;

   std::cout << "年:" << year << std::endl;
   std::cout << "月:" << month << std::endl;
   std::cout << "日:" << day << std::endl;

   return 0;
}

这段代码声明了一个int类型的变量yearmonthday,分别表示年、月和日。然后使用std::cout语句来输出这些变量的值到控制台。输出的结果会在每个变量前附加相应的字符串,例如"年:","月:“和"日:”。

运行这段代码会输出:

年:2022
月:1
日:1

你可以根据需要修改变量的值,并根据你的输出格式进行调整。

0