| TananTanTananTanToink (11) | |
|
What's the difference between std::cout and using namespace std? is std::cout a difference programming? | |
|
|
|
| jumper007 (361) | |||
Nope. Using the using namespace std; is actually making programming easier. I could explain what a namespace is, but that would require you to have some more knowledge about C++ in order to understand. What you need to remember, is that using namespace std; makes your programmer life easier. It's exactly the same as typing:
Hope I could help, ~ Raul ~ | |||
|
Last edited on
|
|||
| TananTanTananTanToink (11) | |
| Thanks i finally understand it now :) | |
|
|
|
| jumper007 (361) | |
|
Well, I don't really get it why some people keep saying that std:: is good. Then why did programers create namespaces ? For their fun ? Probably not. They were created in order to simplify one's code. I, for myself, very often define my own namespaces (in most of my programs). So, it's up to everyone to decide whether to use it or not, but that's my point of view. ~ Raul ~ | |
|
Last edited on
|
|
| Catfish3 (276) | ||||
I'm pretty sure they were created to prevent name collisions. For instance you can have two variables (or functions) with the same name if they're in different namespaces. Go ahead, add using namespace std; to this:
| ||||
|
|
||||
| jumper007 (361) | |||||||
The only thing I can say about it is: Easy!
That's why C++ is a case sensitive programming language. So that you can do what I did, or this -> int Count = 999 //rest of the code , or anything else related to renaming the variable.Example: int countNumberOfOccurrences = 999That's how I write most of my programs. Explicitly write the variable name so that its usage is obvious, despite of your code, which if it would be part of a larger project would be considered (by any programer) as an ambiguous declaration (considering that you had other counters too). EDIT: As I mentioned before, I was/am/will be using namespaces. PS: Just ran your code with Visual C++ 2010:
~ Raul ~ | |||||||
|
Last edited on
|
|||||||
| JLBorges (1754) | ||
> because there is no need of using <algorithm>#include <algorithm> is required for useing std::min() in a portable manner.It is possible that on a particular implementation, #include <iostream> has gratuitously included a header which has std::min()> int _count = 777;
> Just ran your code with Visual C++ 2010: You don't have #include <algorithm>
| ||
|
|
||
| Catfish3 (276) | |
Doesn't have #include <cstdlib> either.You're missing the point, jumper007. Whenever you write using namespace x;, you're making namespace x disappear.You're not "using" that namespace, you're throwing it away. Then you have to worry about name collisions. | |
|
Last edited on
|
|
| jumper007 (361) | |
|
@JLB Nope. My code ran perfectly under Visual C++ 2010 without <algorithm> or <cstdlib>. Yes, underscored variable names are used for namespaces. As I already said, I declare namespaces in most of my big projects, so I am used to declare them like that. @Catfish I got the point. The problem is that you didn't. I got used to declaring/using namespaces. I won't change my programming style just for the sake of avoiding name collisions. As I define my own namespaces, I can give variables different names. It's easy for me to avoid that. Sorry if sounds bad, but that's how I like doing things. PS: Message sent from my tablet pc, so excuse the possible mistakes. ~ Raul ~ | |
|
|
|
| cire (2347) | ||
He didn't say it wouldn't. What he said is that reliance on it working is not portable. Indeed, that same code you say compiled in VC++10, won't compile in VC++11. | ||
|
|
||
| Framework (3237) | |||||||
Qualifying an identifier with its scope is more explicit than "using namespace X" -- at least we know where the identifier came from. In addition, qualifying an identifier on a name-space level actually assists the compiler with symbol look-up. If one is "using namespace std" and "using namespace Other", the compiler would have to look through both name-spaces to find the symbol. By qualifying the identifier with the name-space's identifier, the compiler knows exactly where to look.
Also, if you're going to be "using namespace" all the time, then there's no point in having one. Wazzak | |||||||
|
Last edited on
|
|||||||
| strongdrink (456) | |
| I personally prefer to avoid using namespace as well. Helps with clarity. | |
|
|
|
| moorecm (1826) | |
| I prefer to use it. Always avoid it in header files, though. | |
|
|
|