Can I include iostream header file into custom namespace?
c++, namespaces, std
Solution
Short answer: No.
Long answer: Well, not really. You can fake it, though. You can declare it outside and use using statements inside the namespace, like this:
#include <iostream>
namespace A
{
using std::cout;
};
int main(){
A::cout << "\nSample";
system("PAUSE");
return 0;
}
You cannot localize a library, because even if it had access in A, it would not have access in the standard namespace.
Also, "The other problem is that the qualified names inside the namespace would be A::std::cout, but the library would not contain names qualified with the outer namespace." thanks Jonathon Leffler.
If the problem is that you don't want to let other people know what all your code can do, you could have your own cpp file to include iostream in, and have the namespace defined there. Then you just include that in main (or whatever) and let the programmer know what he can and cannot do.
Problem
``` namespace A { #include <iostream> }; int main(){ A::std::cout << "\nSample"; return 0; } ```