Visual Studio: Create a Hello World app in C?

∥☆過路亽.° 提交于 2019-12-10 14:44:36

问题


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.

(I'm hoping that the compiler and debugger will be built in.)


回答1:


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

Edit: I'm still using 2005 on this machine, so it might not be in the same place, but try this

  • 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)"



回答2:


New project/Win32 Console Application/Empty project.

Add a file called "hello.c" (important that it's .c)

Type out a basic hello-world:

#include <stdio.h>

int main()
{
    printf("Hello world\n");
    return 0;
}

Compile, execute... PROFIT!




回答3:


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.aspx Good Luck.



来源:https://stackoverflow.com/questions/2170169/visual-studio-create-a-hello-world-app-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!