有很多朋友想用c++写游戏代码,但能力所限,有一些功能不会用
在这里我就介绍一下有帮助的函数
注:这些函数均在
#include<bits/stdc++.h>
#include<windows.h>
库中
等待
代码:
Sleep(等待时长,单位:毫秒);
应用:
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
cout<<"1秒后输出:Hello,world"<<endl;
Sleep(1000);
cout<<"Hello,world";
return 0;
}
清屏
代码:
system("cls");
应用:
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
cout<<"Hello,world"<<endl;
Sleep(1000);
system("cls");
return 0;
}
按任意键继续
代码:
system("pause");
应用:
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
cout<<"Hello,world"<<endl;
system("pause");
return 0;
}
打开运行文件
注意,只能是运行文件
代码:
system("路径");//路径中“\”,应该有两个,且路径中不能有空格
应用:
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
system("C:\\Users\\pc\\Desktop\\1.exe");
return 0;
}
4.命令
代码:
system("命令");//cmd,和cmd中的命令,具体命令请Win+R打开cmp后输入help查看
应用:
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
system("cmd");
return 0;
}
制作不易,点个赞吧