Quote:What is "using namespace std ;" ?That expands declarations in a namespace called "std" to the current scope.
Imagine you're talking with your friends about Bamboori being a good person and having a nice beard ..etc. It turns out there's a girl in your class with the name Bamboori, and your classmates think you're talking about this girl (oops). Now you talk a lot about Bamboori in your class, and now you have 2 options to clarify. Either you always say "LFE's Bamboori" - like "LFE's Bamboori burns pizza" and "LFE's Bamboori has a cool beard" -, or you just make it clear to everybody that whenever you say any name of a user that's on LFE, you're referring to that person on LFE and not to a person in your school. After that, you can always just say "Bamboori burns pizza" and everybody would understand you're referring to LFE's. You basically told them you'll be
using namespace LFE.
Similarly, you can tell us on LFE about the girl in your class called Bamboori either by referring to her as "MySchool's Bamboori" (or easier maybe, just write
MySchool::Bamboori), or you tell us I'm
using namespace MySchooland we'll understand that whenever you say Bamboori afterwards that you're referring to the girl in your school.
|
C++-Code:
namespace LFE { int Bamboori = 18947; int A_Man = 12821; int STM = 14145; // etc.. }; namespace MySchool { int Bamboori = 1738415; int Jack = 12491271; // etc.. }; MySchool::Bamboori += 2; // give her 2 things LFE::Bamboori -= 3; // take 3 things using namespace LFE; // right now, we're talking about LFE Bamboori -= 5; // take 5 things from Bamboori MySchool::Bamboori // give 5 things to your school's Bamboori |
Now
coutis an object put inside a namespace called "std" together with many other. You're free to declare
using namespace std;, or to be safe from ambiguity in case there's some other object called "cout", you can just refer to
std::couteverywhere. Doing the latter is good practice.
![[Image: signature.png]](http://s3.postimg.org/wedqxlk3n/signature.png)
A-Engine: A new beat em up game engine inspired by LF2. Coming soon
A-Engine Dev Blog - Update #8: Timeout

Chat
