- C语言从入门到精通(第6版)
- 明日科技编著
- 1376字
- 2024-12-27 19:51:27
1.6.2 Visual Studio 2022
Microsoft Visual Studio(简称VS)是微软公司推出的开发工具集,也是目前最流行的Windows平台应用程序的集成开发环境之一。Visual Studio不仅可以编写C语言程序,还可以开发C++、C#、ASP.NET等,用其编写的代码适用于微软支持的所有平台。下面以Visual Studio 2022社区版的安装为例,讲解具体的安装过程和使用方法。
1.Visual Studio 2022的下载
在浏览器中输入地址https://www.visualstudio.com/zh-hans/downloads/,打开如图1.32所示的下载页面,单击社区版下面的“免费下载”按钮,即可下载Visual Studio 2022社区版。
2.Visual Studio 2022的安装
Visual Studio社区版的安装文件是可执行文件(exe),其名称为VisualStudioSetup.exe。下面介绍Visual Studio 2022社区版的安装过程。
(1)双击安装文件VisualStudioSetup.exe,开始安装。
(2)Visual Studio 2022的安装启动界面如图1.33所示,单击“继续”按钮。

图1.32 下载Visual Studio 2022

图1.33 Visual Studio 2022安装启动界面
(3)程序加载完成后,自动跳转到安装选择界面,如图1.34所示。选中“使用C++的桌面开发”和“通用Windows平台开发”复选框(其他复选框,读者可根据需要确定是否安装),在下面的“位置”处选择要安装的路径,这里不建议安装在系统盘上,可选择一个其他磁盘进行安装。设置完成后,单击“安装”按钮。

图1.34 Visual Studio 2022安装选择界面
(4)跳转到如图1.35所示的安装进度界面,等待一段时间后,即可完成安装。

图1.35 Visual Studio 2022安装进度界面
(5)在系统“开始”菜单中选择Visual Studio 2022程序,如图1.36所示,启动Visual Studio 2022。
注意
在安装Visual Studio 2022开发环境时,一定要确保计算机处于联网状态,否则无法正常安装。
如果是第一次启动Visual Studio 2022,会出现如图1.37所示的提示框,单击“以后再说”超链接,进入Visual Studio 2022开发环境的“开始使用”界面,如图1.38所示。

图1.36 启动Visual Studio 2022程序

图1.37 启动Visual Studio 2022

图1.38 Visual Studio 2022“开始使用”界面
3.Visual Studio 2022的使用
(1)打开Visual Studio 2022开发环境,单击“创建新项目”选项,然后在打开的界面中选择“空项目”选项,并单击“下一步”按钮,如图1.39所示。
(2)打开“配置新项目”对话框,在“项目名称”文本框中输入文件名称,在“位置”下拉列表框中设置文件保存地址(可通过按钮修改文件存储位置),如图1.40所示。最后单击“创建”按钮,打开如图1.41所示的窗口。

图1.39 创建新文件

图1.40 创建C源文件
(3)选择“解决方案资源管理器”中的Demo,右击“源文件”选项,在弹出的快捷菜单中选择“添加”→“新建项”命令,如图1.42所示,或者按Shift+Ctrl+A组合键,打开“添加新项”对话框。

图1.41 创建项目界面

图1.42 添加项目界面
(4)打开“添加新项”对话框,如图1.43所示,左侧选择Visual C++选项,右侧列表框中将显示可创建的不同文件类型。因为要创建C源文件,因此这里选择选项,在下方的“名称”文本框中输入要创建的C文件名称,如demo.c,在“位置”下拉列表框中设置文件的保存地址,最后单击“添加”按钮。

图1.43 添加新项
注意
因为要创建C源文件,所以在文本框中将默认扩展名.cpp改为.c。例如,创建名称为demo的C源文件,文本框中应改为demo.c。
(5)此时已添加了一个C文件demo.c,如图1.44所示。

图1.44 完成添加C文件
(6)将代码写入demo.c文件中,如图1.45所示。
(7)代码编写完之后,接下来就要编译程序了。在菜单栏中选择“生成”→“编译”命令,如图1.46所示,或者按Ctrl+F7快捷键,编译程序。

图1.45 输入代码

图1.46 编译程序
(8)编译结束后,如在输出工作空间的位置输出“生成:成功1个,失败0个,最新0个,跳过0个”,则表示编译成功。此时将得到一个可执行文件。
(9)在菜单栏中选择“调试”→“开始执行(不调试)”命令,如图1.47所示,或者按Ctrl+F5快捷键,运行程序,结果如图1.48所示。

图1.47 运行程序

图1.48 运行结果