- I am using Red Hat Linux 7.2.
To
create a C++ application, open the Home Directory (it should have a
shortcut on the top left corner of the desktop; otherwise, from the
Taskbar, click Start -> KDE menus -> Home Directory)
- The
title bar and the address combo box should display your username. For
this exercise, I am logged with the root username. Therefore, my title
bar and the address combo box display file:/root
With your username selected, right-click in the right frame and click Create New -> Directory... 
- Type Exercise1 and click OK
- On the right frame, make sure the Exercise1 directory is created (because I will refer to it).
- Start a text editor. I use gedit, which is available at Start -> Programs -> Applications -> gedit
- In the text editor, type the following:
#include <iostream.h>int main(){ cout << “C++ is fun!!!\n”; return 0;}
|

- Save your file. If you are using gedit like me, on the main menu, click File -> Save As...
- Under the Directory header in the left list, double-click the Up One Level button ../
If you see your user name in the left list, fine. Otherwise, double-click ../ again.
- On the left list, double-click your user name (for me that would be root/) to open you personal directory
- On the left list, double-click the Exercise1/ directory we created.
- In the Selection: text box, type the name of the file as Exo.cpp and click OK
- To execute the program, open the Terminal: Start -> System -> Terminal.
In the Terminal window, you should see [UserName@localhost Username]$ For example, mine is [root@localhost root]$
- This ensures that you are in your personal directory. To change to the directory that hosts your exercise, type cd Exercise1
Now the new folder should be inside the square brackets. Mine is [Username@localhost Exercise1]$
- To compile the program, we will use the free g++ compiler. Therefore, type:
g++ Exo.cpp
- For example, on mine, I type [jezoo@localhost Exercise1]$ g++ Exo.cpp
- You may receive one warning. For now, don't worry.
- To execute the program, type ./a.out and press Enter
- This
is because the executable file, named a with the extension .out has
been created one folder up from the actual location of the C++ file.
For example, on mine, I type [root@localhost Exercise1]$ ./a.out
- To
check the a.out file that was created when compiling, return to the
Home Directory window and navigate to the
/home/UserName/Exercise1/Exo
|
Tidak ada komentar:
Posting Komentar