Shut down PC via C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Shut down PC via C++

Hello guys! I need a small help. I want to turn off my pc after some time but i want a program that accepts an input and then pass it to the function "system". I know if i put seconds (f.e 3600 ) and not use the variable "tim" that the program will work. Is there any way to do so? here is my code: https://code.sololearn.com/c66dBstGgjoE/#cpp thanks anyway :D

16th Jan 2018, 10:21 PM
Nick Pp
Nick Pp - avatar
4 Answers
+ 2
you arent using the variable, you are using the string "tim"
16th Jan 2018, 10:24 PM
Jeremy
Jeremy - avatar
+ 2
have you converted value of tim to string? read about std::to_string function. and then do like: system("first part" + tim_string + "second part"); I think it should work.
17th Jan 2018, 12:17 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 1
You have a point! I tried it But it didn't work... Or I did something wrong... :/
16th Jan 2018, 10:35 PM
Nick Pp
Nick Pp - avatar
+ 1
Thank you guys very much. I am sorry about the days that gone without answering. I used "kurwius" answer and now the exe works fine!! I am able to shut down my pc right at the time(minutes) that I want to! Be well!
4th Feb 2018, 8:34 PM
Nick Pp
Nick Pp - avatar