How To Print "Hello World" Using C++ Language
Introduction
If you are a learner and you are thinking about starting to learn any programming language, then solving problems with the language along with learning the fundamentals is a must thing do.
In that aspect, all of us start learning any programming language by printing something in the console/terminal, to be more specific, we start with writing Hello World!
. As I am trying to make the series Solve Problems Using C++ a successful series, I am also starting this series with Hello World. 😊
General Code Without using namespace std
#include <iostream> // iostream = input output stream
int main()
{
std:: cout << "Hello World"; // cout = console out / console output
return 0;
}
Firstly, we need to use the header, and I am using the common iostream
header file. iostream
is basically the abbreviation or the short form for Input-Output stream. As we are printing something in the console/terminal, we are using the standard input/output (cout
/cin
) here. Therefore, we are using this header file for now.
Each C++ program execution process starts from the main()
function. Then in the main()
function, we are adding our block of code. Here, as I simply want to print something in the console, I am using cout
, and it is the short form for console out/console output. I am using the standard output form, and therefore using the std::
to specify that explicitly.
After then, I am telling it to return 0
if the code executes successfully. You can remove the return 0
if you want. The code will work itself successfully.
Here, you see that I am using std::
explicitly, and I have to do that each time I want to print something using cout
or take input from the user using cin
. That seems kind of a hassle sometimes. I can reduce that hassle fully!
Code Using using namespace std
If I do not want to specify that I want the standard cin
/ cout
each time I write cin
or cout
, then I can add using namespace std
just after the header file. It will work exactly like earlier, and I also do not even need to write std::
each time I write cin
/cout
.
#include <iostream> // iostream = input output stream
using namespace std;
int main()
{
cout << "Hello World"; // cout = console out / console output
return 0;
}
That's it! 😉
Thank you for reading the article. If you do not want to miss any future updates from my blog, then make sure to subscribe to my newsletter.
Also, make sure to follow me in other media as well.
📹 YouTube Channel (Bengali): Fahim Bin Amin - Bengali
📹 YouTube Channel (English): Fahim Bin Amin - English
⭐ Website: fahimbinamin.com
🔍 GitHub: FahimFBA
✈️ Twitter: Fahim_FBA