How to run / execute a c++ file / program through command prompt / terminal in linux / windows / ubuntu

Step 1 : Open Terminal

Step 2 : Go to the directory where your .cpp file is located.

Eg: cd /home/test/test.cpp (for ubuntu)

or

Eg: cd D:\Test\test.cpp (for windows)


/******************** test.cpp ********************/

#include <iostream>
int main()
 {
 std::cout << "My first C++ program\n";
 return 585;
 }
/******************** test.cpp ********************/

Step 3 : Execute the following command

 g++ test.cpp -o test

Step 4 : The following command will create a test.exe file

Step 5 : Once test.exe is created your cpp file has been compiled successfully.
Now execute the following command
./test

Step 6 : You can see the o/p of test.cpp

Advertisements

About krishjlk

http://www.facebook.com/krishna.kanth.121

One response to “How to run / execute a c++ file / program through command prompt / terminal in linux / windows / ubuntu”

  1. sayeed says :

    too small to understand….. but so important…….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: