
에벤트 루프에서 now() 함수는 시간을 반환하는 데 사용됩니다.
이 함수는 현재 시스템의 시간을 반환하며, 에벤트 루프에서 사용하는 시점에 시간이 정확하게 반환됩니다.
이 함수는 일반적으로 타이머나 스케줄링과 관련된 작업에서 사용됩니다.
예를 들어, 특정 시간이 지난 후에 특정 작업을 수행하도록 스케줄링하고 싶을 때, now() 함수를 사용하여 현재 시간을 확인하고, 특정 시간이 지난 후에 작업을 수행할 수 있습니다.
now() 함수의 사용 예시는 다음과 같습니다.
#hostingforum.kr
cpp
#include
#include
int main() {
auto now = std::chrono::high_resolution_clock::now();
auto now_time = std::chrono::duration_cast(now.time_since_epoch()).count();
std::cout << "현재 시간: " << now_time << std::endl;
// 특정 시간이 지난 후에 작업을 수행할 수 있습니다.
auto target_time = now_time + 5; // 5초 후에 작업을 수행할 수 있습니다.
while (true) {
auto current_time = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
if (current_time >= target_time) {
break;
}
}
std::cout << "5초가 지났습니다." << std::endl;
return 0;
}
이 예시는 now() 함수를 사용하여 현재 시간을 확인하고, 특정 시간이 지난 후에 작업을 수행하는 방법을 보여줍니다.
2025-06-22 13:36