This is the second part of the [Borland C++ builder programming series].Here you will learn on how to create,compile & excute console application.Reader is supposed to have atleast Borland C++ builder 5 or Higher.Borland CPP Builder can be used to create many type of applications that include win32,console or opengl or DLL’s etc.If you are beginner in C++ or C then most of the time you are working with console applications to compile assignment problems.Console appliations are widely used for teaching examples as they can demonstrate most of the esential of language.With console programming,you will get start with language easily without having to worry about GUI design.
What is Console application?
Console application is 32bit program runs in command prompt under windows 2k or Xp.With console appliation you don’t need to worry about the GUI of application,all your code is concentrated towards application.Prior to desktop GUI,console applications was the face of operating systems.Console programs still exist with embeded system,BIOS etc.So think of them as starting point in C++ programming.
Creating Console applications
Start Borland C++ Builder.From the main menu,choose File | New.This will open up the new items dialog box.In the New Items dialog box, click Console Wizard and click OK.In the Console Wizard, make sure that the C++ radio button is selected,also check the console application then Click OK.The Console Application option tells the IDE to create a console program.You are presented with a file as follows:
#pragma hdrstop // Line 1
#pragma argsused // Line 2
int main(int argc, char* argv[])
{
return 0;
}
Code written at the line 1,stops the listing of header files inclusion in the compiler.So you’ve to include all you header file above this line.Line 2 is included by C++ Builder to prevent a warning message if the parameters to main( ) are not used.You have to add following line above the Line1.
#include <iostream>
and this below the Line 1:
using namespace std;
The above code makes usall set to execute but it’ll show nothing on console.So let’s write something on it.Most of the programming tutorials start with Hello world text.So let’s honor the tradition,try adding following line under the function main().
cout<<“Hello world”<<endl;
Now your code should look like this:
#include “iostream”
#pragma hdrstop
using namespace std;
#pragma argsused
int main(int argc, char* argv[])
{
cout<<“Hello world”<<endl;
return 0;
}
Now you’ve to save this file.Do this by selecting File | Save All.Save the file with extension .cpp.You can run the program directly from the IDE by selecting Run | Run.Did you see that? Your program just work correctly,but you didn’t tell it to stop for a while.Try adding the following line below cout statement.
cin.get();
This will pause the screen till you hit any key on keyboard or you can even use getchar();.If you want to use system pause function then you’ve to include cstlib header file.
use #include “cstdlib” before the Line1 of above program (use less then & greater than symbol instead of quotes) & then use following statement after cout statement.
system(“pause”);
This was very simple example but this will give you kickstart in borland builder.You have to practice on console appliation before getting your hands dirty on GUI.Whenever you create console application follow the same steps for console wizrd & for entering source code.To learn more about C++ programming pick up any book in C++,i suggest Robert lafore Object oriented programming in C++.
In next article,i’ll tell you how to create windows application using Borland C++ builder.If you find any error or typos post it in comments.Thank you for reading.Any feedback is welcome.
CAD Services says
nice information about Borland C++ Builder