JW P
JW P

Reputation: 183

How to combine a numerical variable with a chrono literal?

Let's say I have a variable int x = 2000 and I want to make a thread sleep for 'x milliseconds'. How do I combine the chrono literal ms with x?

I tried stuff like this:

std::this_thread::sleep_for((x)ms);
std::this_thread::sleep_for(xms);

Thank you for your time!

Upvotes: 2

Views: 1701

Answers (1)

JW P
JW P

Reputation: 183

Thanks to @DeiDei:

std::this_thread::sleep_for(std::chrono::milliseconds(x)) fixed my problem!

Upvotes: 5

Related Questions