1.下载安装SublimeText3绿色版,链接可以查看我的资源。

https://download.csdn.net/download/weixin_41645983/11102351

2.工具 -> 编译系统 -> 新建编译系统,粘贴以下内容保存

{
	"path": "C:/MinGW/bin",
	"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
	"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
	"working_dir": "${file_path}",
	"selector": "source.c, source.c++",

	"variants":
	[
		{
			"name": "Run",
			"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && timer \"${file_path}/${file_base_name}\" < in.txt > out.txt"
		}
	]
}

 3.新建工作空间文件夹,包括以下文件

SublimeText3配置c++编译运行并使用文件输入输出和程序运行时间

4.timer的代码:

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <windows.h>
using namespace std;

int main(int argc, char** argv)
{
	clock_t begin = clock();
	system(argv[1]);
	double used = 1000.0 * double(clock() - begin) / CLOCKS_PER_SEC - 200.0;
	if (used < 0) used = 0.0;
	printf("------------------------------\n");
	printf("Time used: %.2lf ms.\n", used);
	return 0;
}

5.现在在code.cpp中写入程序,编译时选择刚刚新建的编译系统,之后直接Ctrl+B即可。窗口布局也可调整如下更方便。

SublimeText3配置c++编译运行并使用文件输入输出和程序运行时间

相关文章: