tags:

views:

63

answers:

3

My question is pretty much the title. Example

#include <iostream>

int main()
{
   using std::cout; //legal?
   { 
      using std::cin; //legal?
   }
}
+4  A: 

Yes, it's legal. In fact, it's preferred over doing it at file scope...

kotlinski
I am sorry but I haven't heard of such a thing as a file scope
Armen Tsirunyan
Does the same apply to `using namespace`?
sje397
@sje397: Yes, it does.
usta
A: 

Why didn't you test it? It works alright.

progo
@progo - because it isn't a criterion
Armen Tsirunyan
+3  A: 
  • 7.3.3 The using declaration

A using-declaration introduces a name into the declarative region in which the using-declaration appears.

And, since someone asked in a comment about using namespace:

  • 7.3.4 Using directive

A using-directive shall not appear in class scope, but may appear in namespace scope or in block scope.

Michael Burr