delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/15/15:32:42

From: khan AT xraylith DOT wisc DOT edu (Mumit Khan)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: cout + latest version?
Date: 15 Nov 1999 17:18:29 GMT
Organization: Center for X-ray Lithography, UW-Madison
Lines: 61
Message-ID: <80pf95$16bs$1@news.doit.wisc.edu>
References: <3823718F DOT 51A3 AT tin DOT it> <806t6a$1u3i AT enews4 DOT newsguy DOT com> <809lmf$o2o$1 AT news DOT doit DOT wisc DOT edu> <38301C64 DOT B476CAC0 AT nortelnetworks DOT com>
NNTP-Posting-Host: modi.xraylith.wisc.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <38301C64 DOT B476CAC0 AT nortelnetworks DOT com>,
Ian Chapman  <ichapman AT nortelnetworks DOT com> wrote:
>Mumit,
>	I'm not at all able to see what the issue is.  cout works like any text
>book will tell you.  I did not  know that you could get away with out
>the *.h in the include bit.  Wonder why?  and what digs with this std? 
>I'm not learning from you, I'm sure that you can be more enlightening
>rather than coming through as a smartie.

[ Ian, if you've also posted a note as well as emailing it, please do 
mention that in the email. Save me some typing. ]

The issue is quite simple: All of iostreams live in the std namespace,
and unless you specifically (1) qualify explicitly, or (2) import 
specific symbols or all the symbols from the std namespace, you're not
allowed to use cout, cerr, etc.

Here's an example of (1):
  
  #include <iostream>
  int 
  main ()
  {
    std::cout << "Hello world" << std::endl;
  }

Here's an example of (2.a):

  #include <iostream>
  using std::cout;
  using std::endl;
  int 
  main ()
  {
    cout << "Hello world" << endl;
  }


Here's an example of (2.b):

  #include <iostream>
  using namespace std;
  int 
  main ()
  {
    cout << "Hello world" << endl;
  }

Some vendors have chosen to use headers with .h suffix as a backward
compatibility header; eg., if you include <iostream.h>, it will 
implicitly do a `using namespace std;' for you, or put all the names 
in the global namespace. However, this is by no means standard, but
it just a convention used by some of the vendors.

Newer books such as Stroustrup 3rd and a few others cover this in some
detail.

Regards,
Mumit


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019