+ 11
What will happen if we do not declare namespace?
13 odpowiedzi
+ 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;
}
+ 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.
+ 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";
}
+ 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.
+ 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.
+ 2
if you don't declare namespace, the there words will not be typed in std(standard library)
0
namespace is recent addition to c++ so if u are using old traditional dosbox it is not required
0
i never write using namespace std; and it doesn't make any difference to the program
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.
- 1
can we say similar to xmlns ?.
- 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
- 2
a lot of errors
- 4
in turbo7-- no error
in Dev-cpp,code block --warning