Can anyone exaplin or give me a link to an explanation fo the laetst c++ standards?
I gather std::cout<< should be used rather than just cout<< for example.
What other changes are there? and what does the std:: part mean?
Can anyone exaplin or give me a link to an explanation fo the laetst c++ standards?
I gather std::cout<< should be used rather than just cout<< for example.
What other changes are there? and what does the std:: part mean?
std:: introduces the namespace from which you are selecting a name, thus
cout << ...
assumes that the namespace is already visible to the process at that point, you've used a "using namespace std;" for example,
std::cout << ....
specifically says use the "std" namespace now, for this name resolution.
Neither is more standard then the other, as both are part of the ANSI standard. What you will find is from a stylistic point of view std::cout tends to be favoured over a using clause.
That said, if you are using a lot of items from the a specific namespace, use a using, the resolution operators simply clutter the code.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
So arwe you saying if i declare
then i can jsut type cout<<, I thought i still had to type std::cout<<Code:using namspace std;
sry im a bit confused
> then i can jsut type cout<<,
Well if you go for the brute-force using namespace std;
That just gets everything from the standard name space
Imagine you have a large project where two different things define cout
using namespace std;
using namespace foo;
Then you might do
std::cout << "hello";
foo::cout << "world";
But you could no longer do
cout << "woe is me";
For small programs which only use the standard namespace, its probably OK
For large programs with many namespaces, you'll definitely want to be more specific about your intentions.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
ok, so can you tell me what namspace does? whats the difference between std and foo?
The thing is I havent been taught this by my teacher so im trying to work it out myself....
(you might remmeber i was the guy who was taught by his teacher to use void main() (which btw i dont any more ) and also was using an ancient Borland compiler (ive now chanegd to dev-c++)
std is well, standard - everybody gets a std namespace
foo is made up - you can define a foo namespace and you can call it whatever you want
explosive::finder;
There's an example.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I think of namespaces as just another identifier. Say I had two friends named Smith. One lived Chicago, the other in Paris. If I said I was going to visit my friend Smith, you wouldn't know which place I was going. But if I said I was going to visit my friend Smith in Paris, you'd know. The city in which my friends live is equivalent to a namespace in that it allows you to differentiate between two different things with the same name. The default namespace is std, but you can declare a namespace at any time you want and give it any name you want. Then you just have to tell the compiler which version of the item you want to use by indicating the namespace in which it resides.
ok thank you for clearing that up for me
If you don't like typing but still don't want to clutter the global namespace, the following thing is legal:Code:#include <iostream> int main() { using namespace std; cout << "Hej ! "; }
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling