我的环境是 win10 + vs2005
1.打开visual studio 2005
<span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic4.zhimg.com/50/e9fe11c02c2c21465f5b03eb6e74040c_hd.jpg" data-rawwidth="220" data-rawheight="146" class="content_image" width="220"/></span>
新建一个项目
<span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic1.zhimg.com/50/3410c9388c302b596dc2f2c790c60370_hd.jpg" data-rawwidth="471" data-rawheight="163" class="origin_image zh-lightbox-thumb" width="471" data-original="https://pic1.zhimg.com/3410c9388c302b596dc2f2c790c60370_r.jpg"/></span> 选择Win32控制台应用程序,意思是运行的结果会出现在控制台 <span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic1.zhimg.com/50/5d68ee635cf3600c786b6d51fa9ae446_hd.jpg" data-rawwidth="578" data-rawheight="517" class="origin_image zh-lightbox-thumb" width="578" data-original="https://pic1.zhimg.com/5d68ee635cf3600c786b6d51fa9ae446_r.jpg"/></span> <span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic1.zhimg.com/50/84c9c3a12d12ea1d1509c55f9e97b68d_hd.jpg" data-rawwidth="665" data-rawheight="567" class="origin_image zh-lightbox-thumb" width="665" data-original="https://pic1.zhimg.com/84c9c3a12d12ea1d1509c55f9e97b68d_r.jpg"/></span> <span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic4.zhimg.com/50/768bc3064966797588d63b2324d70642_hd.jpg" data-rawwidth="657" data-rawheight="561" class="origin_image zh-lightbox-thumb" width="657" data-original="https://pic4.zhimg.com/768bc3064966797588d63b2324d70642_r.jpg"/></span> 右边就会出现刚才新建的“知乎”项目 <span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic4.zhimg.com/50/a66e58c0863ef1932c104785eb3707cc_hd.jpg" data-rawwidth="348" data-rawheight="314" class="content_image" width="348"/></span> 你写的C程序是源文件来的,所以在源文件位置,右键添加C语言文件 <span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic1.zhimg.com/50/39ab815a193c0b7a60f8e5d2bfa819c0_hd.jpg" data-rawwidth="534" data-rawheight="232" class="origin_image zh-lightbox-thumb" width="534" data-original="https://pic1.zhimg.com/39ab815a193c0b7a60f8e5d2bfa819c0_r.jpg"/></span> 选择C++文件,默认出现文件名为 “源.cpp” , cpp的意思是 c plus plus,是C++文件来的。需要把后缀名,从cpp改成c,代表C语言文件
<span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic4.zhimg.com/50/58f767f81047ce66676c67e9654b4eec_hd.jpg" data-rawwidth="541" data-rawheight="543" class="origin_image zh-lightbox-thumb" width="541" data-original="https://pic4.zhimg.com/58f767f81047ce66676c67e9654b4eec_r.jpg"/></span> 右边出现了刚才新建的C文件
<span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic1.zhimg.com/50/3bd6aca4479bb1588470446a6c1e5329_hd.jpg" data-rawwidth="188" data-rawheight="144" class="content_image" width="188"/></span> 现在可以写代码了
#include <stdio.h> main() { printf("你好 知乎\n"); }
点击保存,生成你的“知乎”项目,这样项目里头的所有文件,都会被编译(包括刚才C文件)
<span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic2.zhimg.com/50/fd02337780b554fd2097f4815baf7e70_hd.jpg" data-rawwidth="321" data-rawheight="189" class="content_image" width="321"/></span> <span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic1.zhimg.com/50/3fe8cc3182e893dc50effe9213e6eea3_hd.jpg" data-rawwidth="605" data-rawheight="166" class="origin_image zh-lightbox-thumb" width="605" data-original="https://pic1.zhimg.com/3fe8cc3182e893dc50effe9213e6eea3_r.jpg"/></span>
编译完以后,就可以运行了!
然后,我来补充下 安装完编译时遇到的一些其他问题。
1.编译后“闪退”。 使用vs编译,编译框会一闪而过 。
如不想每次都选择【调试-开始执行(不调试)】,只要在程序最后加上system("pause"); 编译框便会停留。
<span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic1.zhimg.com/50/v2-789b07f515ef721955ff1841b3ed80d7_hd.jpg" data-rawwidth="350" data-rawheight="276" class="content_image" width="350"/></span>
2.编译后提示函数错误什么的。
<span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic4.zhimg.com/50/v2-7cc8e7d10dfc1f67b0589c3f8084af32_hd.jpg" data-rawwidth="656" data-rawheight="79" class="origin_image zh-lightbox-thumb" width="656" data-original="https://pic4.zhimg.com/v2-7cc8e7d10dfc1f67b0589c3f8084af32_r.jpg"/></span>
解决方法,项目》属性--》C/C++--》预处理器--》预处理器定义--》下拉-编译--》在最后填入【_CRT_SECURE_NO_WARNINGS】就行了。
<span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic3.zhimg.com/50/v2-becec360d5b5e80a4897350a039dfc1b_hd.jpg" data-rawwidth="914" data-rawheight="224" class="origin_image zh-lightbox-thumb" width="914" data-original="https://pic3.zhimg.com/v2-becec360d5b5e80a4897350a039dfc1b_r.jpg"/></span> <span style="font-family: "PingFang SC", 宋体;" data-mce-style="font-family: 'PingFang SC', 宋体;"><img src="https://pic2.zhimg.com/50/v2-c2e37eaa4acea60eb5112b64ffdc7118_hd.jpg" data-rawwidth="258" data-rawheight="146" class="content_image" width="258"/></span>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下