Hello World, three different ways? Which is best?

I'm currently teaching myself C++ through the use of online resources and books.
And I have noticed something. Each of the resources teaches the "Hello World" program a bit differently, and is structured differently.

Source 1:
1
2
3
4
5
6
7
8
9
10
#include <iostream>

using namespace std;

int main()
{
  cout<<"Hello World!";
  cin.get();
  return 0;
}

Source 2:
1
2
3
4
5
6
7
8
9
#include <iostream>
using std::cout;
using std::endl;

int main()
{
  cout << "Hello World!" << endl;
  return 0;
}

Source 3:
1
2
3
4
5
6
7
#include <iostream>

int main()
{
 std::cout<<"Hello World!";
 return 0;
}


So my question is: Which of these is the "best" way to go about making a program, or are they all interchangeable and you use whichever way you were taught.

Thanks!
The third one is the proper way to do it, and I suggest learning the standard namespace. It will alleviate confusion later one when using different things in the namespace because you forgot to "use" the namespace std; it is also good practice. Just know what the using namespace does, essentially allows you to type less, and what is actually contained in the std namespace, such as strings, cin, cout, containers, etc.
The first waits for you to hit enter before terminating, the second one is "normal", the third one does not print a newline after the sentence. The best one is the one you want.
I would say the third one is best!

Welcome to c++. Pretty much everything can be done different, always choose the style that fits you best for the moment and not what is "The best".

Good luck!
Topic archived. No new replies allowed.