C/C++调用DOS命令

C/C++调用DOS命令

使用system(“…”);
C要#include <stdlib.h>
C++直接(只要iostream

C:

1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
#include <stdlib.h>
int main(){
//显示当前文件夹内容
system("dir");
//创建目录
system("mkdir philippian_test");
//在该目录中创建hehe.txt文件
system("touch philippian_test/hehe.txt");
return 0;
}
1
2
3
4
5
6
7
该程序,

1. 显示当前文件夹内容

2. 创建名字为“philippian_test”的文件夹(目录)

3. 在该目录里面创建文件“hehe.txt”

C++:

1
2
3
4
5
6
#include <iostream>
using namespace std;
int main(int argc, char *argv[]){
system("date");
return 0;
}
1
用date命令显示当前日期:
Donate? comment?