문제

백준 10699번 오늘 날짜

해결 과정

간단한 출력 문제이다. 오늘 날짜를 출력하면 된다. C++에서는 ctime 헤더를 사용하면 쉽게 풀 수 있다.

예시 답안

C++ 코드

Baekjoon/10xxx/10699.cpp
#include <ctime>
#include <iostream>
using namespace std;
 
int main() {
  time_t t = time(nullptr);
  struct tm tm = *localtime(&t);
 
  cout << tm.tm_year + 1900 << '-';
  if (tm.tm_mon + 1 < 10) cout << '0';
  cout << tm.tm_mon + 1 << '-';
  if (tm.tm_mday < 10) cout << '0';
  cout << tm.tm_mday << endl;
  return 0;
}

문제 풀이 팁

C++에서 출력은 std::cout을 사용한다.

#include <iostream>을 사용하면 std::cout을 사용할 수 있다.

std::endl은 다음 줄로 넘어가는 역할을 한다.

using namespace std;를 사용하면 std::를 생략할 수 있다.

추가 학습 자료