[编程代码] 解决dev-c++无法EXE中编辑关机秒数

3168 0
EricCfstar 2022-1-9 23:56:11 来自手机 | 显示全部楼层 |阅读模式
一般在新Dev-c++中引用cmd命令时,大家都用system(“”);的结构。但是,这个结构中的内容不能直接更改。比方说,我想让此台电脑在30秒后关机,那我需要打system(“shutdown -s -t 30”);这行代码,但是在生成的exe程序中,无法把“30”秒更改成其他秒数。
我的朋友Jia为了解决这个问题,和我做了一个程序,程序如下:

//Writen by Jia and Eric
#include<bits/stdc++.h>
using namespace std;
int main(){
        string tempString;       
        cout<<"您想在几秒后关机:";       
        int num_1;        cin>>num_1;       
        while(num_1 != 0){
                        tempString = char((num_1 % 10) + 48) + tempString;
                        num_1 = num_1 / 10;
                        }
        char chr[255];        for(int i = 0; i <= tempString.size(); i++){       
                chr[i] = tempString[i];
                }       
        char cmdTemp[] = "shutdown -s -t ";       
        strcat(cmdTemp, chr);        cout<<"此电脑将在"<<tempString<<"秒后关机!"<<endl;       
        system(cmdTemp);
        system("pause");
        return 0;
}


超凡星曜实验室
QQ:3345615469
邮箱:eric.etstudio@qq.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

EricCfstar

等待验证会员

关注
  • 4
    主题
  • 0
    粉丝
  • 0
    关注
这家伙很懒,什么都没留下!

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行