ad

Thursday, 24 November 2011

How to Use Visual Studio to Write C Programs

Visual Studio is the GUI application front end to Microsoft's development environment. Programmers use Visual Studio to create and manage development projects for executables, DLLs and other software components. Visual Studio allows you to edit, compile and incrementally link source code written in C/C++, C#, J# or Visual Basic. Visual Studio distinguishes itself from earlier Microsoft developer products (such as Visual C++ 6.0), which focused specifically on a particular source language. The goal of the Studio projects is to consolidate all application development into a seamless, integrated GUI.

Because C is effectively a subset of C++, Visual Studio manages C programs as C++ projects. Therefore, writing a C program for use in Visual Studio mainly involves the programmer excluding C++-specific language features from his code, yet still using the C++ project options in the GUI.
1.

Create a new project:

On the File menu, point to New, then click Project….
2.

From the Visual C++ project types, click Win32, then click Win32 Console Application.
3.

Enter a project name.

By default, the solution that contains the project has the same name as the new project, though you can enter a different name. You can enter a different location for the project if you wish.

Click OK to create the new project.
4.

In the Win32 Application Wizard, select Empty Project and click Finish.
5.

If Solution Explorer is not visible, click Solution Explorer on the View menu.
6.

Add a new source file to the project:
*

Right-click on the Source Files folder in Solution Explorer and point to Add and click New Item.
*

Click C++ File (.cpp) from the Code node, enter a file name, and then click Add.

The .cpp file appears in the Source Files folder in Solution Explorer and a tabbed window appears where you type in the code.
7.

Click in the newly created tab in Visual Studio and type in a valid C++ program that uses the Standard C++ Library, or copy and paste one of the sample programs.

For example, you can use the set::find (STL Samples) sample program in the Standard Template Library Samples topics in the help. See How to: Compile a Code Example from the Help Topics for information on copying a sample program to the Clipboard.

If you use the sample program for this procedure, notice the using namespace std; directive. This allows the program to use cout and endl without requiring fully qualified names (std::cout and std::endl).
8.

On the Build menu, click Build Solution.

The Output window displays information about the compilation progress, such as the location of the build log and a message indicating that the build succeeded.
9.

On the Debug menu, click Start without Debugging.

If you used the sample program, a command window is displayed that shows whether certain integers are found in the set.




source:

msdn

No comments:

Post a Comment