
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
How to Edit, Compile, and Execute a C++ Program?
Create a new cpp file using your text editor. Enter the following in it −
#include<iostream> int main() { std::cout << "Hello world"; }
Save this file as source.cpp.
Once you've got your compiler and source program ready, it is very easy to compile and run a C++ program. Assuming that you've installed GCC compiler, and you have a source.cpp file that you want to compile, follow the following instructions to compile and run it.
Open a new terminal window or cmd if you are on windows.
Change the directory to the directory in which you have your source.cpp file. For example, if it is in C:/Users/Dell/Documents, enter your command line −
$ cd 'C:/Users/Dell/Documents'
Now enter the following command to compile the source file using g++.
$ g++ -o <name-you-want-to-give> source.cpp
In place of <name-you-want-to-give> replace it by any name like myprogram, etc.
Run it! Now you can run the program using −
$ ./myprogram
- Related Articles
- How to compile and execute C# programs on Linux?
- How to compile and execute C# programs on Windows?
- How to compile and execute C# programs on Mac OS?
- How to compile a java program
- How to compile and run the C++ program?
- How can we edit a java program?
- How to compile & run a Java program using Command Prompt?\n
- How to execute zombie and orphan process in a single C program?
- How to Compile a Lua Executable?
- How to compile a Typescript file?
- How to compile 32-bit program on 64- bit gcc in C and C++
- How to execute a COBOL-DB2 program PROGA of plan PLANA?
- Python Program to Edit objects inside tuple
- How to edit a comboBox in JavaFX?
- How can Tensorflow be used to train and compile a CNN model?
