Topic: MSVC and "Hello World


Author: "Jim Barry" <jim.barry@bigfoot.com>
Date: 1999/08/02
Raw View
Valentin Bonnard wrote:

> Your code is incorrect: endl isn't applied to any
> arguments, so there are no namespaces to search it
> in, except ::.

OK, my posting was the result of an apparent erratum in C++PL3 and a bit
of wishful thinking.

It would be nice if there was a way to import all manipulators in one
go. I think it would be possible if the standard library did something
like:

namespace std
{
  namespace manipulators
  {
    using std::endl;
    // etc.
  }
}

Then you could just say "using namespace std::manipulators".
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: David R Tribble <david@tribble.com>
Date: 1999/08/03
Raw View
Al Stevens wrote:
>
>> As I see it, it provides a, perhaps unwelcome, incentive to write
>> "using std::endl".
>
> Or a, perhaps welcome, incentive to write:
>       std::cout << "Hello World!" << std::endl;

Or perhaps it's an incentive to fall back on proven technology:

    std::printf("Hello World!\n");

Those newfangled thingies can be so confusing sometimes.

-- David R. Tribble, david@tribble.com --
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Darin Adler" <darin@bentspoon.com>
Date: 1999/07/31
Raw View
Jim Barry <jim.barry@bigfoot.com> wrote:

> Here's one that has been annoying me for ages. As I understand it,
> Koenig lookup should ensure that following code compiles (and this is
> supported by C++PL3 21.4.6.2):
>
> #include <iostream>
>
> int main()
> {
>   std::cout << "Hello World!" << endl;
> }

I don't agree.

The expression "endl" is evaluated before the call to operator<<. Koenig
lookup doesn't affect the lookup of the endl symbol.

> MSVC barfs with "error C2065: 'endl' : undeclared identifier". What
> gives? How come it finds std::operator<< but not std::endl? (Polite
> answers only, please ;) I'm puzzled that I couldn't find anything on
> DejaNews about it.

std::operator<<() is a function call with std::cout as a parameter, so
Koenig lookup applies. std::endl is the name of a function object in the
library, so Koenig lookup does not apply.

> This is more than a mere annoyance, as it provides an unwelcome
> incentive to write "using namespace std".

As I see it, it provides a, perhaps unwelcome, incentive to write "using
std::endl".

    -- Darin
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Frank" <nospmfrank_l@hotmail.com>
Date: 1999/08/01
Raw View
OK, here are two working programs, with variations (addressing your
problem):

//    Hello World #1
//
#include <iostream.h>

int main()
{
 cout << "Hello World!" << endl;
 return 0;
}

--------------------------------------------------------------------
//    Hello World #2
//
#include <iostream>

int main()
{
 std::cout << "Hello World!" << std::endl;
 return 0;
}

So, your 'endl' you used was from <iostream.h> instead of <iostream>.  The
correct keyword you needed was 'std::endl'.

///    Frank (remove 'nospm' to email)


Jim Barry <jim.barry@bigfoot.com> wrote in message
news:009401bedaac$b34b01e0$6400000a@thermoteknix.co.uk...
> Here's one that has been annoying me for ages. As I understand it,
> Koenig lookup should ensure that following code compiles (and this is
> supported by C++PL3 21.4.6.2):
>
> #include <iostream>
>
> int main()
> {
>   std::cout << "Hello World!" << endl;
> }
>
> MSVC barfs with "error C2065: 'endl' : undeclared identifier". What
> gives? How come it finds std::operator<< but not std::endl? (Polite
> answers only, please ;) I'm puzzled that I couldn't find anything on
> DejaNews about it.
>
> This is more than a mere annoyance, as it provides an unwelcome
> incentive to write "using namespace std".



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/08/01
Raw View
"Darin Adler" <darin@bentspoon.com> writes:

> std::operator<<() is a function call with std::cout as a parameter, so
> Koenig lookup applies. std::endl is the name of a function object in the
> library, so Koenig lookup does not apply.

You are right: Koenig lookup does not apply here. The reason is
simple; section 3.4.2 starts

>> When an unqualified name is used as the postfix-expression in a
>> function call (5.2.2), other namespaces not considered during the
>> usual unqualified lookup (3.4.1) may be searched, and
>> namespace-scope friend function declarations (11.4) not otherwise
>> visible may be found.

endl is not 'used as the postfix-expression in a function
call'. Instead, it is merely used as an identifier forming an
expression.

By the same pattern, Koenig-lookup would not apply to operator<<, either.
Fortunately, there is 13.3.1.2, [over.match.oper]/3:

>> The set of non-member candidates is the result of the unqualified
>> lookup of operator@ in the context of the expression according to
>> the usual rules for name lookup in unqualified function calls
>> (3.4.2) except that all member functions are ignored.

So, for operators, you don't have Koenig lookup in the strict sense;
instead, it is a modified form which finds candidates even if there
are members as candidates also.

Regards,
Martin
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/08/02
Raw View
Jim Barry wrote:

> Here's one that has been annoying me for ages. As I understand it,
> Koenig lookup should ensure that following code compiles (and this is
> supported by C++PL3 21.4.6.2):

I doupt it.

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

Your code is incorrect: endl isn't applied to any
arguments, so there are no namespaces to search it
in, except ::.

--

Valentin Bonnard
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: kuehl@horn.fmi.uni-konstanz.de (Dietmar Kuehl)
Date: 1999/08/02
Raw View
Hi,
Jim Barry (jim.barry@bigfoot.com) wrote:
: Here's one that has been annoying me for ages. As I understand it,
: Koenig lookup should ensure that following code compiles (and this is
: supported by C++PL3 21.4.6.2):

C++PL3 is wrong in this case. Koenig lookup is used to find a function
in the namespaces of the arguments to this function. This example tries
to find an argument, which just happens to be a function, using Koenig
lookup.

: #include <iostream>

: int main()
: {
:   std::cout << "Hello World!" << endl;
: }

This has to be

   std::cout << "Hello World!" << std::endl;

Actually, I would recomment

   std::cout << "Hellow World!\n";

Since this avoids an unnecessary synchronization with the external
representation and, en passant, also resolves the lookup problem.
--
<mailto:dietmar.kuehl@claas-solutions.de>
<http://www.informatik.uni-konstanz.de/~kuehl/>
I am a realistic optimist - that's why I appear to be slightly pessimistic
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Al Stevens" <alstevens@midifitz.com>
Date: 1999/08/02
Raw View
>As I see it, it provides a, perhaps unwelcome, incentive to write "using
>std::endl".

Or a, perhaps welcome, incentive to write:
      std::cout << "Hello World!" << std::endl;
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Jim Barry" <jim.barry@bigfoot.com>
Date: 1999/08/02
Raw View
Dietmar Kuehl wrote:

> C++PL3 is wrong in this case.

I guess that answers my question then. ;-)
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Jim Barry" <jim.barry@bigfoot.com>
Date: 1999/08/02
Raw View
Frank wrote:

> OK, here are two working programs, with variations (addressing your
> problem):

My question was "why doesn't this work", not "how do I make this work",
but thanks anyway.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Jim Barry" <jim.barry@bigfoot.com>
Date: 1999/08/02
Raw View
Darin Adler wrote:
>
> As I see it, it provides a, perhaps unwelcome, incentive to write
"using
> std::endl".

And:

using std::setbase;
using std::setfill;
using std::setprecision;
// etc.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Jim Barry" <jim.barry@bigfoot.com>
Date: 1999/07/31
Raw View
Here's one that has been annoying me for ages. As I understand it,
Koenig lookup should ensure that following code compiles (and this is
supported by C++PL3 21.4.6.2):

#include <iostream>

int main()
{
  std::cout << "Hello World!" << endl;
}

MSVC barfs with "error C2065: 'endl' : undeclared identifier". What
gives? How come it finds std::operator<< but not std::endl? (Polite
answers only, please ;) I'm puzzled that I couldn't find anything on
DejaNews about it.

This is more than a mere annoyance, as it provides an unwelcome
incentive to write "using namespace std".

--
Jim Barry, Thermoteknix Systems Ltd., Cambridge, UK.
http://www.geocities.com/SiliconValley/2060
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]