如何在 Visual Studio 2013 中添加新的 C 文件
How do I add a new C file in Visual Studio 2013
我是 Visual Studio 2013 的新手,过去使用过 2010。如何添加 C 文件?似乎只有 C++ 的选项。我不使用 C++,只使用 C,并且编译为 ANSI C99。这是我选择“添加新项目”时对话框的样子:
如您所见,它可以选择添加 C++ 文件或头文件,但不能选择 C 文件。
简答:不能。
Visual C++ 是由 C++ 编译器支持的 C++ IDE。它支持C和C++的公共子集(因为它也是有效的C++),但不直接支持C。它只部分支持C99。所以没办法把一个会编译成C99的文件添加到工程中。
您不能使用 Visual Studio 创建 C 程序。您可以通过创建新项目、选择 Win32 控制台应用程序、添加现有文件并从那里修改来编辑现有的简单 C 程序。但是没有从头开始的 C 支持。有关如何操作的更多详细信息,请参阅 related。
这个link:http://www.swarthmore.edu/NatSci/tali/E15/Visual_C.html
可能会有帮助。
link 是这样说的:
将 Microsoft Visual Studio 用于简单的 C 程序
Microsoft Visual C++ Express 的免费版本可在以下位置获得:http://msdn2.microsoft.com/en-us/express/aa700735.aspx
要编辑您的 C 程序:
From the main menu select File -> New -> Project
In the New Project window:
Under Project types, select Win32 - Win32 Console Application
Name your project, and specify a location for your project directory
Click 'OK', then 'next'
In the Application Wizard:
Select Console application
Select Empty project
Deselect Precompiled header
Once the project has been created, in the window on the left hand side you should see three folders:
Header Files
Resource Files
Source Files
Right-click on Source Files and Select Add-> New Item
Select Code, and give the file a name
The default here will be a file with a *.cpp extension (for a C++ file). After creating the file, save it as a *.c file.
编译和运行:
Press the green play button.
By default, you will be running in debug mode and it will run your code and bring up the command window.
To prevent the command window from closing as soon as the program finishes execution, add the following line to the end of your main function:
getchar();
This library function waits for any input key, and will therefore keep your console window open until a key is pressed.
将文件添加到解决方案后,右键单击它,然后在
C/C++->Advanced->Compile As,点击Compile as C Code (/TC)
重命名文件是不够的,你需要告诉Visual Studio2013是一个C文件。 Visual Studio 2013 不支持 C99 标准,但至少会使用 C ABI,你会限制编译器只接受 C 语句。
Visual Studio 2015 完全实现了 C99 标准库,但依赖于 Visual C++ 编译器尚不支持的编译器功能的任何库功能除外(例如,<tgmath.h>
未实现).
您可以创建新项目模板(添加C文件插件),
您可以下载:Visual Studio - New Item Template.zip
将 ZIP 文件解压到:
C:\Users\USERNAME\Documents\Visual Studio 2013\Templates\ItemTemplates\
或(对于 VS2012):
C:\Users\USERNAME\Documents\Visual Studio 2013\Templates\ItemTemplates\Visual C++ Project
或者如果您想将其放在“代码”子类别下:
C:\Users\USERNAME\Documents\Visual Studio 2013\Templates\ItemTemplates\Visual C++ Project\Code
或者您可以阅读此 Tutorial 为 Visual Studio.
创建自定义 项目模板
我是 Visual Studio 2013 的新手,过去使用过 2010。如何添加 C 文件?似乎只有 C++ 的选项。我不使用 C++,只使用 C,并且编译为 ANSI C99。这是我选择“添加新项目”时对话框的样子:
如您所见,它可以选择添加 C++ 文件或头文件,但不能选择 C 文件。
简答:不能。
Visual C++ 是由 C++ 编译器支持的 C++ IDE。它支持C和C++的公共子集(因为它也是有效的C++),但不直接支持C。它只部分支持C99。所以没办法把一个会编译成C99的文件添加到工程中。
您不能使用 Visual Studio 创建 C 程序。您可以通过创建新项目、选择 Win32 控制台应用程序、添加现有文件并从那里修改来编辑现有的简单 C 程序。但是没有从头开始的 C 支持。有关如何操作的更多详细信息,请参阅 related。
这个link:http://www.swarthmore.edu/NatSci/tali/E15/Visual_C.html 可能会有帮助。
link 是这样说的:
将 Microsoft Visual Studio 用于简单的 C 程序
Microsoft Visual C++ Express 的免费版本可在以下位置获得:http://msdn2.microsoft.com/en-us/express/aa700735.aspx
要编辑您的 C 程序:
From the main menu select File -> New -> Project
In the New Project window:
Under Project types, select Win32 - Win32 Console Application
Name your project, and specify a location for your project directory
Click 'OK', then 'next'
In the Application Wizard:
Select Console application
Select Empty project
Deselect Precompiled header
Once the project has been created, in the window on the left hand side you should see three folders:
Header Files
Resource Files
Source Files
Right-click on Source Files and Select Add-> New Item
Select Code, and give the file a name
The default here will be a file with a *.cpp extension (for a C++ file). After creating the file, save it as a *.c file.
编译和运行:
Press the green play button.
By default, you will be running in debug mode and it will run your code and bring up the command window.
To prevent the command window from closing as soon as the program finishes execution, add the following line to the end of your main function:
getchar();
This library function waits for any input key, and will therefore keep your console window open until a key is pressed.
将文件添加到解决方案后,右键单击它,然后在 C/C++->Advanced->Compile As,点击Compile as C Code (/TC)
重命名文件是不够的,你需要告诉Visual Studio2013是一个C文件。 Visual Studio 2013 不支持 C99 标准,但至少会使用 C ABI,你会限制编译器只接受 C 语句。
Visual Studio 2015 完全实现了 C99 标准库,但依赖于 Visual C++ 编译器尚不支持的编译器功能的任何库功能除外(例如,<tgmath.h>
未实现).
您可以创建新项目模板(添加C文件插件),
您可以下载:Visual Studio - New Item Template.zip
将 ZIP 文件解压到:
C:\Users\USERNAME\Documents\Visual Studio 2013\Templates\ItemTemplates\
或(对于 VS2012):
C:\Users\USERNAME\Documents\Visual Studio 2013\Templates\ItemTemplates\Visual C++ Project
或者如果您想将其放在“代码”子类别下:
C:\Users\USERNAME\Documents\Visual Studio 2013\Templates\ItemTemplates\Visual C++ Project\Code
或者您可以阅读此 Tutorial 为 Visual Studio.
创建自定义 项目模板