472,354 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

How to disable "using namespace"

For example, at the beginning of the C++ program,
I say "using namespace std;"

However, in the middle of the program, I want to disable "using
namespace std;".

Do you know how to do that?

Thanks!
Peng
Jul 22 '05 #1
5 6510
Peng Yu wrote:
For example, at the beginning of the C++ program,
I say "using namespace std;"

However, in the middle of the program, I want to disable "using
namespace std;".

Do you know how to do that?


There is no way. Don't say 'using namespace std;' in the first place.

V
Jul 22 '05 #2
Peng Yu wrote:
For example, at the beginning of the C++ program,
I say "using namespace std;"

However, in the middle of the program, I want to disable "using
namespace std;".

Do you know how to do that?

Thanks!
Peng


I find it easier en more convenient to place std:: in front of what's in
this namespace.

cfr. std::cout << "easier" << std::endl;
Jul 22 '05 #3
Peng Yu wrote:
For example, at the beginning of the C++ program,
I say "using namespace std;"

However, in the middle of the program, I want to disable "using
namespace std;".

Do you know how to do that?


The answer is: not.
You can't do it. That's the reason why you shouldn't write "using namespace
std;" in the first place.

Jul 22 '05 #4


Peng Yu wrote:
For example, at the beginning of the C++ program,
I say "using namespace std;"

However, in the middle of the program, I want to disable "using
namespace std;".

Do you know how to do that?

Thanks!
Peng


As others have pointed out there is no way of undoing a using
statement... if you *must* do this modularize your program so that the
modules you do the using statement in actually need it and those that
don't need it don't get it. Another way is to reorganize a module and
put the dependencies on the standard name space at the end, so that the
first part of the file needn't have the using.

I think you've had enough people yell at you for doing it to begin with
tho :).

David
Jul 22 '05 #5
Peng Yu posted:
For example, at the beginning of the C++ program,
I say "using namespace std;"

However, in the middle of the program, I want to disable "using
namespace std;".

Do you know how to do that?

Thanks!
Peng

You can limit it to only where you want it, as in:
#include <iostream>

int main()
{
using namespace std;

cout << "Monkey!";

void SomeFunc();

SomeFunc();
}
void SomeFunc()
{
cout << "Monkey!";

//Compile error
}

-JKop
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: cppaddict | last post by:
It is typical to put the line: using namespace std; at the top of a file which makes use of std library objects. To take a simple example: #include <iostream> using namespace std;
2
by: Jacek Dziedzic | last post by:
Is it valid to use a "using namespace foo" (as opposed to using foo::bar which I'm sure is legal) within a class declaration? My compiler rejects it, but I've been told it's valid. Can anyone...
17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
4
by: Teddy | last post by:
If I use just a STL container such as std::vector in my program. Is "using std::vector;" better than "using namespace std" ? Does "using namespace std" cost ?
6
by: AlexD_UK | last post by:
When I create a new C++ project of type "Class Library (.NET)", I am unable to then add the following line of code : using namespace std If I do, I get the following error on compilation :...
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.