开发者

Visual Studio: Create a Hello World app in C?

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+开发者_如何学JAVA+, but none for C.

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


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!


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜