How to Compile C++ code in Microsoft Visual Studio 2005

advertisement
How to Compile C++ code in Microsoft Visual Studio 2005
In order to compile simple C++ program in Microsoft Visual Studio 2005, you need to follow the
following steps:
1.
2.
3.
4.
5.
Create a new project. Choose Win 32 and Win 32 Console Application.
Enter a name in the Name box below.
Now press the Next button and then the Finish button.
This will generate a file called name.cpp where name is your entered project name.
Delete everything from the name.cpp file except the line “#include "stdafx.h"” and then
include the following two lines at the beginning of the source code.
#include <iostream>
using namespace std;
6. Write your code
7. Press F7 To compile. Note, you may get an error message that say "fatal error C1853:
'Debug\name.pch' precompiled header file is from a previous version of the compiler,
or the precompiled header is C++ and you are using it from C (or vice versa)"
8. How to solve fatal error C1853: Right-click on your C++ file in Solution Explorer panel, and go to
Properties dialog. Then change the value of C/C++ -> Precompiled Header -> Create/Use
Precompiled Header field to "Not Using Precompiled Header".
9. Run the program by pressing CTRL+F5
An example is given below:
#include <iostream>
using namespace std;
class shs
{
private:
int n1;
int n2;
public:
shs(){ n1=3; n2=6; }
int add(int x, int y){return (x+y);}
int add(){ return (n1+n2);}
int access(){return n1;}
int addref (shs&);
};
int addref(shs& c)
{return (c.add() + c.add()); }
int main(){
shs a;
shs b;
cout << a.add(4,5);
return 0;}
How to Compile C++ code in Microsoft Visual Studio 2005
How to debug in Visual C++ 2005 Express Edition:
========================================
1. F9 to insert break points
2. F5 to start debugging
3. F10 or F11 for step forward
5. F7 to stop debugging
How to Run C++ source code in Visual C++ 2005 Express Edition:
==========================================
1. Ctrl+F7 or F7 to compile and linking
2. Ctrl+F5 to run or execute
How to turn on line numbers in the editor:
==================================
1. Go to: Tools -> Options -> Text Editor -> C/C++ -> General
2. Check the box "Line Numbers" -> OK
Download