How to compile and run your program.


1.

Open a text editor and type your program. You can use an editor of your choice, though pico editor will be demonstrated. To open a file in pico type:
pico filename
This will create a file named filename. Your file should have an extension .cpp (that is C plus plus, for example main.cpp)

 

2.

After you type your program you have to save it(overwrite):
^ o (Hold Ctrl key on your keyboard and press o)

  Verify the filename is correct when saving, and hit Enter

3.

Exit from text editor
^x

 

4.

To compile type:
g++ -o myprog filename

If you do not have any errors you will see a new command line prompt. Otherwise you will see error messages. In this case you have to open your file in text editor, correct them, and compile again. It is important to remember that compilers do not detect all errors. They will detect syntactic errors, that is omitted braces, commas, etc., or out-of-range errors. They will not be able to detect any logical errors (if you are doing something the wrong way).

 

5.

To run your file type:
./myprog
You will see your output on the screen.

 


Back