Making your first program in C++
#include <iostream>
int main() {
std::cout<<“Hello World!”;
}
Ok, now rewrite the above in Dev-C++. To save, go to file and choose save_as > choose a location > type the filename > add a .cpp suffix to the filename (if your filename was hello, it’s now hello.cpp) > click save
To run you program, click execute and choose compile and run.
If Dev-C++ fail, to run your program; it means you used the copy and paste tactic. So, go to your codes to delete and rewrite the double quotes.
Understanding these code
#include <iostream>
As the name says it, Dev-C++ was designed for C++. However, it can also work for C because C++ was developed in C. Therefore, the above line tell Dev-C++ that we are creating a C++ program. If it was C we would use #include <stdio.h>. iostream is short for input output stream. We will learn more about headers next time.
int main() creates a function called main and two curry brackets { } are which hold the instructions for this function. The two parenthesis () are which indicate it is a function. Once you try to run a program made in C++, it call a function call main. A C++ program can’t run with no main function.
std::cout is C++ command to display text on the screen. Std is short for standard and cout is short for console output. The two opening arrow brackets << indicate the string “Hello World!” is passed to the cout command. The double quotes are used to hold strings in C++. String is another name for text.
© Mihigo ER Anaja
Write to me for more;
0 Comments