|
|
|||||||||||
Basics The struture of a program . By developing a basic console application you will learn the basics of programming in C++. After you understand the structure of a C++ program you will ( hopefully ) see that C++ is not as hard as it is made out to be. Creating your first application will only require three easy steps. In the first step you will set up the compiler, the second step you will insert the code into the text editing area of Dev C++ and finally you need to compile and link your code to create your programs executable file.
Source Code Source Code - This contains the instructions you want give the computer. Compiled - The best way to think of this is as a spell checker for programming, it checks for code errors. Object Code - If their are no errors the source code is turned into whats known as an object file(intermediate code). Linked - All object files are combined together to form an EXE. EXE
- This is the end result. This is the file you can run. An Example Type in, or copy & paste the code below into the text editing area of Dev C++ - #include <iostream.h> main()
} Now all you have to do to create your first program is click Compile and Run from the Execute menu. Enter the name for the source file and wait for the compiler to build the code. The time it takes to compile depends on the speed of your computer. If the program won't compile properly then either the code hasn't been copied correctly or the compile settings are incorrect. For some help post a message in the forum. Let me explain the example line by line, #include <iostream.h> Just type in the above code and forget about it for now, all will be explained in time... main()
The above piece of code is what is called a function. This particular function is very important because it must be included in every DOS program. { You can begin typing in statements into the main function after this character. cout<<"Hello"<<endl; The keyword cout is used to send data to the display. << Is called a insertion operator in C++ and is used to output data. (The default output device is the monitor ). The text to be displayed on the screen is positioned in between the two " symbols. endl ends the line. Finally ; tells the compiler that the statement has ended. system ("PAUSE"); Sometimes in some Dev C++ applications the program will close before you have a chance to use it, putting this command in will make sure this doesn't happen. return(0); This means that the main function returns nothing, you don't have to know what it means right now it will be explained on the Part functions. }
This just means that the main function has ended.
|