int i = 10;
system("shutdown /t %i"); // 錯誤:%i 不會被展開為變量值
#include
#include
int time = 30;
std::ostringstream cmd;
cmd << "shutdown -s -t " << time;
system(cmd.str().c_str());
#ifdef _WIN32
cmd << "shutdown -s -t " << time;
#else
cmd << "shutdown -h +" << (time/60); // Linux 分鐘單位
#endif