问题描述
std :: this_thread :: sleep_for()或usleep()
在main()中使用哪个更好?这可能很愚蠢,但是我是C ++ 11功能的新手。
解决方法
前者实际上是可移植的C ++函数。后者是过时的,不可移植的POSIX函数(由nanosleep
代替,后者仍不可移植)。使用std::this_thread::sleep_for()
,它可能会根据可用的{/ {1}}或适当的方式或系统提供的其他功能来实现。
std :: this_thread :: sleep_for()或usleep()
在main()中使用哪个更好?这可能很愚蠢,但是我是C ++ 11功能的新手。
前者实际上是可移植的C ++函数。后者是过时的,不可移植的POSIX函数(由nanosleep
代替,后者仍不可移植)。使用std::this_thread::sleep_for()
,它可能会根据可用的{/ {1}}或适当的方式或系统提供的其他功能来实现。