+ 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?

4th Oct 2016, 7:14 AM
Asia Nealy
Asia Nealy - avatar
3 Answers
+ 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.
27th Oct 2016, 8:31 PM
Neen
Neen - avatar
+ 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
13th Feb 2018, 10:57 AM
ANIWENE MADOLOMANI
ANIWENE MADOLOMANI - avatar
0
Thanks for this well written answer
23rd Jun 2017, 4:20 PM
Asia Nealy
Asia Nealy - avatar