如何在win10上实现 " HelloWorld "打印显示

1.下载MinGW
MinGW官方网址:http://www.mingw.org/

2.安装MinGW
运行下载下来的mingw-get-setup文件,会开始解压MinGW安装文件,解压完成后会在桌面出现一个快速安装的快捷方式。点击运行该程序,会出现组件安装选择界面(至少选择mingw32-gcc组件,右键选择 “ Mark for Installtion ”),然后选择菜单栏的 “ Installtion -> apply change "进行安装。(在自己所选择的安装地址下查看,有gcc.exe、g++.exe、gdb.exe说明安装成功)

3.配置MinGW环境变量
新建一个系统环境变量并修改Path系统环境变量
“ 我的电脑 ” -> “ 属性 ” -> “ 高级 ” -> “ 环境变量 ” -> “ 系统变量 ” -> “ 新建 ”
1.新建系统环境变量
变量名:MinGW
变量值(MinGW安装路径):C:\MinGW
2.修改Path系统环境变量
在系统环境变量里的Path变量中添加gcc.exe的路径:%MinGW%\bin
也可以不用新建系统环境变量,而直接在Path系统环境变量中添加gcc.exe的完整路径:C:\MinGW\bin

运行命令行,键入“ gcc -v ”显示GCC版本查看是否配置成功

4.编写C语言代码
新建TXT文本文档" hello ",并修改其后缀 .txt 为 .c。然后在该文本文档中键入以下代码:
#include <stdio.h>
int main()
{
printf("hello, world");
}
然后关闭保存到桌面。

4.编译C代码
运行命令行,在命令行中键入:
gcc desktop\hello.c -o desktop\hello.exe
桌面将会出现一个 hello.exe 的文件。

5.运行编译结果
接着在命令行中键入:
desktop\hello.exe
你将看到命令行中输出了那一句 “hello, world”。(你也可以在桌面直接双击运行该程序,但桌面只会一闪而过一个黑框(实际为命令行))。

网友评论