Visual Studio: Create a Hello World app in C?

2019-06-27 12:51发布

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

3条回答
别忘想泡老子
2楼-- · 2019-06-27 13:02

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!

查看更多
▲ chillily
3楼-- · 2019-06-27 13:06

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)"
查看更多
Juvenile、少年°
4楼-- · 2019-06-27 13:19

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.

查看更多
登录 后发表回答