+ 11

What will happen if we do not declare namespace?

29th Apr 2016, 5:00 PM
Mannan Bansal
Mannan Bansal - avatar
13 Réponses
+ 29
if you don't declare then, you will be typing your hello world program like this: #include <iostream> int main(){ std::cout << "Hello world!!"<<std::endl; return 0; } instead of #include <iostream> using namespace std; int main(){ cout << "Hello world!!" << endl; return 0; }
3rd Dec 2016, 4:02 PM
Core i9
Core i9 - avatar
+ 6
If you don't declare a namespace for a library, you'll be retrieving the inner functions like so: `std::cout`. By declaring a namespace, we are just making the calls to the functions easier to write.
11th Jun 2016, 11:28 AM
Lucius Latham
Lucius Latham - avatar
+ 5
Nothing. But with std more easily to using standart functions, containers and streams. #include<iostream> int main() { std::cout<<"Hello World"; } or #include<iostream> using std::cout; int main() { cout<<"Hello World"; }
10th Dec 2016, 10:17 PM
SUPER_S
SUPER_S - avatar
+ 3
Namespace is just a memory or area in the library of C++ WHERE we have defined the meaning of objects like cin, cout and many others. Remember Namespace std is just one of the Namespace available in c++, there can be other too,. Moreover we can define our own Namespace.
4th May 2016, 5:31 AM
Raju Gautam
Raju Gautam - avatar
+ 2
Imagine that your functions are .exe files on your hard drive, and your variables are data files. Namespaces in this analogy are folders. When you use a using statement, it simply makes a shortcut to those functions and variables. I feel it goes without saying that if you don't create those shortcuts, you have to type out the full path, ie std::cout instead of just cout. Mind you the compiled program isn't changed by the presence of namespaces, really. The only thing that it'd effect I believe would be the decorated function signatures, which you very rarely have to worry about. Using, however, does move the entire namespace into the global namespace, and if you have functions or variables with the same signature, you're going to get compiler errors. Having been in the industry for a while, I can definitely say namespaces are used quite often, but using is used pretty sparingly outside of demos. tl;dr: It just means you'd have to type the full path in for the var or function in question. Namespaces are basically just to organize your code.
1st Dec 2016, 3:27 PM
Nemo
+ 2
if you don't declare namespace, the there words will not be typed in std(standard library)
3rd Dec 2016, 6:58 AM
Kenneth Agyare
0
namespace is recent addition to c++ so if u are using old traditional dosbox it is not required
1st Dec 2016, 6:13 PM
kirankumar A
kirankumar A - avatar
0
i never write using namespace std; and it doesn't make any difference to the program
2nd Dec 2016, 2:55 AM
Rahul Sharma
Rahul Sharma - avatar
0
using namespace std; is used to inform the compiler to look for the io functions in this standard library. If it is not used, the compilation will flag an error that cin/cout is undefined. It is compiler dependent. If you are using turbo cpp, namespace is not required. Most compilers demands the use of namespace.
3rd Dec 2016, 9:13 AM
Sivaprasad K
Sivaprasad K - avatar
- 1
can we say similar to xmlns ?.
6th Dec 2016, 1:58 AM
Balaji Kannadassan
Balaji Kannadassan - avatar
- 1
u have to define extras keyword std::cout and std::cin but in old compilers like dosbox u need not to use extra keyword
6th Dec 2016, 2:56 AM
kirankumar A
kirankumar A - avatar
- 2
a lot of errors
7th Dec 2016, 11:01 AM
Yadagalla Jaswanth Kumar
Yadagalla Jaswanth Kumar - avatar
- 4
in turbo7-- no error in Dev-cpp,code block --warning
6th Dec 2016, 5:47 AM
Dhiraj singh✔️
Dhiraj singh✔️ - avatar