You are here:

C++/using namespace std

Advertisement


Question
a normal program can work properly in turbo c++. then why nowadays it is preferred to use namespace std in all programs as well as books even though it produces error in turbo c++?

Answer
Disclaimer: I have not used Turbo C++ a lot and certainly not in the last 20 years or so.

Short answer:
-------------
You are probably using a C++ implementation from the early 1990's that pre-dates ISO/ANSI standard C++. At this time the features mentioned as causing problems with Turbo C++ did not exist or were only being discussed, implying Turbo C++ would not support them.

Longer Answer:
--------------
You do not state which version of Turbo C++ you are using or what its release date was. However, as far as I can tell unless you have a copy of one of the later Embarcadero Technologies produced Turbo C++ editions from 2006, all other versions of Turbo C++ were released _before_ 1998 when the first version of the ISO/ANSI C++ standard was released (on September 1st according to my copy). The Wikipedia article on Turbo C++ at http://en.wikipedia.org/wiki/Turbo_C%2B%2B has more details on the history of Turbo C++.

Note that since the initial 1998 ISO/ANSO C++ standard release there has been the 2003 bug fix release, the 2007 TR1 library extensions release, the major release in 2011, an intermediate release due this year, 2014 and another major release planned for around 2017. Hence the language and library do not stand still and while care is taken not to break existing code as much as possible (backwards compatibility), code targeting later language versions cannot of course be expected to be compiled using implementations targeting older variants. Sometimes a compiler or library will implement new features before they are officially standardised, but often will need to be tweaked in later versions of the product to comply with the finalised wording - or corrected wording if reported defects in the standard have been fixed.

Bearing the above in mind, a feature called namespaces was introduced with ISO/ANSI C++ that did not feature in pre-standard C++ so I suspect it is probable that most, if not all, pre-2006 versions of Turbo C++ did not support what would have been at the time an up-and-coming feature.

Further, even if namespaces were supported in later 1990's versions of the product then it may well be that the supplied C++ library did not follow the proposed standardisation work including, as there was no standard at the time, not placing standard library names in the std namespace, as dictated by the ISO/ANSI C++ standard.

You might be interested to note the Turbo C++ version 1.01 is available for download and is described as "Antique Software", see:

   http://edn.embarcadero.com/article/21751

Unless you really cannot use a more up to date C++ implementation - for example because you have to use or target computers running only 16-bit MS-DOS / PC-DOS / MS Windows etc. - I strongly suggest you use a more up to date C++ implementation, such as (assuming you are using 32-bit MS Windows):

   MS Visual C++ Express : http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx
   Code::Blocks IDE + MinGW compiler MinGW (http://www.mingw.org/) -  http://www.codeblocks.org/
       http://www.cprogramming.com/code_blocks/ - note the bit about a setup file with mingw in the name!

In fact you might like to generally peruse the CProgramming site:

   http://www.cprogramming.com/

The Getting Started and Set up a C/C++ compiler sections seem of particular relevance.

Hope this is of use.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Ralph McArdell

Expertise

I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.

Experience

My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at http://www.open-std.org/jtc1/sc22/wg21/.

Education/Credentials

©2016 About.com. All rights reserved.