There are various items that must be ready before normal programming may be done on a computer, including :
- Language of Programming: You must decide which language of programming to employ. Programming languages like C++, Java, Python, and others are widely available.
- Text Editor or IDE: You will need a text editor or Integrated Development Environment (IDE) to write and save your program code. Some examples of popular text editors and IDEs include Notepad++, Visual Studio Code, and PyCharm.
How to make a simple program with c++
The following is an example of how to create a simple program in C++ :
#include <iostream>
using namespace std;
int main ( )
{
// Displays the message "Hello World!" on screen
cout << "Hello World!" << endl;
returns 0;
}
- The C++ standard input-output capability is provided by the iostream library, which is loaded using the #include iostream> directive.
- using namespace std; used to shorten writing cout and cin.
- A C++ program's main function, int main(), is a requirement for all programs. The first time the application is run, this function will be used.
- cout << "Hello World!" << endl; used to display the message "Hello World!" on screen.
- returns 0; used to end the main() function and returns a value of 0 as the program output code.
Running C++ Programs :
1. Open a C++ programming text editor or integrated development environment (IDE).
2. Type the program code above in a text editor or IDE.
3. Save the program code with a file name that ends with the extension ".cpp" (for example, "helloworld.cpp").
4. Launch a terminal or command prompt.
5. Change to the directory where the program files are stored using the "cd" command (for example, "cd C:\Users\username\Documents").
6. Compile the program using the command "g++ filename.cpp -o filename.exe" (for example, "g++ helloworld.cpp -o helloworld.exe").
7. Run the program using the "./filename.exe" command (eg "./helloworld.exe").
8. The screen will show the message "Hello World!" from the software.
This is how to write a straightforward C++ program and execute it from the command line or terminal. ✔


Tidak ada komentar:
Posting Komentar