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.
#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.
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.