Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

c++ - using namespace std; in header file

Some people claim that using namespace std; is bad practice. Others say it's OK in it's place. But everyone agrees that putting it in a header file is verboten.

So dear reader, who can explain this from Bjarne Stroustrup's own web site.

http://www.stroustrup.com/Programming/Graphics/std_lib_facilities.h

He didn't even put it at the top where you might notice it, its about 50 lines down.

What's going on here? Are mischievieous hackers out to discredit BS by putting bad code on his web-site?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Did you read the comment at the start of the file?

simple "Programming: Principles and Practice using C++" course header to be used for the first few weeks. It provides the most common standard headers (in the global namespace) and minimal exception/error support.

Students: please don't try to understand the details of headers just yet. All will be explained. This header is primarily used so that you don't have to understand every concept all at once. Revised April 25, 2010: simple_error() added

The idea is so you can get started in the language without having to learn about namespaces day 1 nor worry about which standard headers need to be included for what.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...