Hello all,
Definitely a newbie to C++, not to coding in general. I have very little experience with C#, but… I understand the basics of OOP; Inheritance, Encapsulation, Abstraction and Polymorphism.
Functions/Methods, Parameters/Arguments, Members/Properties.
I'm currently reading the book by Stephen Prata: C++ Prime Plus 6th Edition
Seems pretty good so far! Although I really wouldn't know, since I'm a C++ newbie. :-)
Anywho, I've also watched a bunch of YouTube videos… In the videos, the "using namespace std;"… Is 2 lines right below the last #include directive.
1 2 3 4 5 6 7 8 9
|
#include <iostream>
using namespace std;
int main()
{
return 0;
}
|
For simplicity sake, let's say I was to declare a couple of variables and assign a couple of pointers to those variables right in between the "using namespace" and the "main function".
Couple of global variables, if you will…
That's how it's done, in a lot of the YouTube videos… If not, all of them.
From Stephen Prata's book, doing this is a little dangerous… Not to mention a bit lazy… Mainly for large programs.
To my knowledge, everything under "using namespace std;" will implicitly… Use the "std library".
Now, inside Stephen's book…
1 2 3 4 5 6 7 8
|
#include <iostream>
int main()
{
using namespace std;
return 0;
}
|
Now anything declared above the "main function", will explicitly have to be defined with the "std library".
I'm only on page 45, but… He briefly mentioned that it was better, or… We as beginners are better off learning to explicitly define our use of the "std library".
I suppose my question is: What do you old pros think?
What is the conventional preference?
On where to place the "using namespace std;"?
Or do most of you just explicitly define your usage of the "std library"?
And, have you noticed… Or heard of anybody that is noticed, differences of performance…
Input, feedback, tips or tricks is greatly appreciated in advance!
Rob