visual-studio Visual Studio:在 C 中创建一个 Hello World 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2170169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio: Create a Hello World app in C?
提问by Nick Heiner
How can I create a basic C app in Visual Studio, be it 2010 Ultimate or 2008 Professional? I have searched through the project templates, and can find plenty for C++, but none for C.
如何在 Visual Studio 中创建基本的 C 应用程序,无论是 2010 Ultimate 还是 2008 Professional?我搜索了项目模板,可以找到很多 C++,但没有找到 C。
(I'm hoping that the compiler and debugger will be built in.)
(我希望编译器和调试器将被内置。)
采纳答案by John Knoeller
Visual Studio doesn't have a separate compiler for C, it uses the C++ compiler for C code. You can tell it to restrict itself to legal C syntax by using a compiler switch or by renaming the .cpp file to .c
Visual Studio 没有单独的 C 编译器,它对 C 代码使用 C++ 编译器。您可以通过使用编译器开关或将 .cpp 文件重命名为 .c 来告诉它限制自己使用合法的 C 语法
Edit: I'm still using 2005 on this machine, so it might not be in the same place, but try this
编辑:我还在这台机器上使用 2005,所以它可能不在同一个地方,但试试这个
- Right click on the main.cpp in the solution explorer pane (on the right).
- Choose Properties (bottom of the menu)
- Open up the C/C++ group of properties
- choose Advanced page
- Change "Compile As" property to "Compile as C Code (/TC)"
- 右键单击解决方案资源管理器窗格(右侧)中的 main.cpp。
- 选择属性(菜单底部)
- 打开 C/C++ 属性组
- 选择高级页面
- 将“编译为”属性更改为“编译为 C 代码 (/TC)”
回答by Seva Alekseyev
New project/Win32 Console Application/Empty project.
新项目/Win32 控制台应用程序/空项目。
Add a file called "hello.c" (important that it's .c)
添加一个名为“hello.c”的文件(重要的是它是 .c)
Type out a basic hello-world:
输入一个基本的 hello-world:
#include <stdio.h>
int main()
{
printf("Hello world\n");
return 0;
}
Compile, execute... PROFIT!
编译,执行... 利润!
回答by OulinaArt
In addition to changing the file extension, you may need to change the compiler settings:
Settintgs of Application->C/C++->addition->compiler such...
You must take /TC for basic C and /TP for C++.
https://msdn.microsoft.com/ru-ru/library/032xwy55.aspxGood Luck.
除了更改文件扩展名之外,您可能还需要更改编译器设置:Application->C/C++->addition->compiler 的设置... 对于基本 C 必须采用 /TC,对于 C++ 必须采用 /TP。
https://msdn.microsoft.com/ru-ru/library/032xwy55.aspx祝你好运。

