如何在Sublime Text中运行C和C ++程序

In this tutorial you will learn how to run C and C++ program in sublime text on windows.

在本教程中,您将学习如何在Windows上以高级文字运行C和C ++程序。

It is a very popular and widely used text editor by programmers and developers. Just follow below steps to configure sublime text to compile and run C and C++ programs. I have tested the steps in sublime text 3 but I am sure it will work for any other version also.

它是程序员和开发人员非常流行且广泛使用的文本编辑器。 只需按照以下步骤配置崇高文本即可编译和运行C和C ++程序。 我已经测试了Sublime Text 3中的步骤,但是我确信它也可以在其他版本中使用。

Also Read: Configure Notepad++ to Run C, C++ and Java Programs

另请阅读: 配置Notepad ++以运行C,C ++和Java程序

How to Run C and C++ Programs in Sublime Text

如何在Sublime Text中运行C和C ++程序 (How to Run C and C++ Program in Sublime Text)

Here I consider that you have installed GCC compiler on your system.

在这里,我认为您已经在系统上安装了GCC编译器。

第1部分:在环境变量中添加路径 (Part 1: Adding Path in Environment Variables)

1. Copy the path of bin folder of GCC compiler. In my case the path looks like as shown below, it may be different in your case.

1.复制GCC编译器的bin文件夹路径。 在我的情况下,路径如下所示,但在您的情况下可能有所不同。

C:\Program Files (x86)\CodeBlocks\MinGW\bin

C:\ Program档案(x86)\ CodeBlocks \ MinGW \ bin

2. Now right click on Computer and select Properties. Then click on Advance system settings and after that click on Environment Variables.

2.现在,右键单击计算机,然后选择属性 。 然后单击高级系统设置 ,然后单击环境变量

3. In the next window under System variables find a variable with name Path. Select it and click on Edit button.

3.在下一个窗口的系统变量下,找到名称为Path的变量。 选择它,然后单击“ 编辑”按钮。

4. In Variable value text field go to end and then type semicolon and then paste the path of bin folder that you copied. See below screenshot.

4.在“ 变量值”文本字段中,转到结尾,然后键入分号,然后粘贴复制的bin文件夹的路径。 请参见下面的屏幕截图。

How to Run C and C++ Programs in Sublime Text

5. Finally click on all OK buttons to save the settings.

5.最后单击所有确定按钮以保存设置。

第2部分:配置崇高文本 (Part 2: Configuring Sublime Text)

Open sublime text and go to Tools > Build System > New Build System and then paste the following lines in it.

打开sublime文本,然后转到“ 工具”>“构建系统”>“新构建系统” ,然后在其中粘贴以下几行。

For C:

对于C:

{
"shell_cmd" : "gcc $file_name -o ${file_base_name}",
"working_dir" : "$file_path",
 
"variants":
[
	{
		"name": "Run",
		"shell_cmd": "gcc $file_name -o ${file_base_name} && ${file_path}/${file_base_name}"
	}
]
}

Press ctrl+s and then save it with file name C_RUN.

ctrl + s ,然后将其保存为文件名C_RUN。

For C++:

对于C ++:

{
"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}\" && \"${file_path}/${file_base_name}\""
	}
]
}

Press ctrl+s and then save it with file name CPP_RUN.

ctrl + s ,然后将其保存为文件名CPP_RUN。

For running a program go to Tools > Build With and then select C_RUN – Run or CPP_RUN – Run according to the language you are using.

要运行程序,请转到“ 工具”>“构建方式” ,然后根据您使用的语言选择“ C_RUN –运行”或“ CPP_RUN –运行”

影片教学 (Video Tutorial)

If you have any query then ask in comment section, I will try to solve it.

如果您有任何疑问,请在评论部分询问,我将尝试解决它。

翻译自: https://www.thecrazyprogrammer.com/2017/04/how-to-run-c-and-c-program-in-sublime-text.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值