Video Coming Soon...

Created by Zed A. Shaw Updated 2026-04-18 04:15:27

39: sleep

Implement the first command line tool, sleep.

View Source file sleep.cpp Only

//https://www.gnu.org/software/coreutils/manual/html_node/sleep-invocation.html 
#include <fmt/core.h>
#include <chrono>
#include <thread>
#include <string>

int main(int argc, char* argv[]) {
  if(argc != 2) {
    fmt::println("USAGE: sleep [seconds]");
    return 1;
  }

  int time = std::stoi(argv[1]);
  std::chrono::seconds wait_for{time};

  std::this_thread::sleep_for(wait_for);
}
Previous Lesson Next Lesson

Register for Learn C++ the Hard Way

Register to gain access to additional videos which demonstrate each exercise. Videos are priced to cover the cost of hosting.