+ 2
So I learned that using a namespace is bad practice. If I plan on writing out the libraries how do I go about it?
3 Réponses
+ 6
It's true that using a namespace directly can be considered bad practice, but it's especially true for std.
If you leave out the "using namespace std;" at the top of your code, you can still access functions from std by using the "::" (scope resolution) operator. For example:
#include <iostream>
void main()
{
std::cout << "hello world";
}
The line "std::cout" simply means that you're looking for "cout" in the "std" namespace.
+ 3
there are many bad practices in programming.. even coping a code then pasting it else where then editing it is a bad practice. however.. i would encourage you to know when to perform a bad practice to your advantange. as you can see. using namespace std would save you alot of codes instead of writing std::cin.. or std::cout every time you are dealing with input and output streams.. more codes means less a bigger program.. as programmers we try our best to reduce amount of codes we write.. thus namespaces become very useful
0
Thanks for this well written answer