 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
knilges Guest
|
Posted: Wed Jan 18, 2006 3:53 pm Post subject: stoopid begineer with a question |
|
|
I am trying to build a Hello World program in C++. I am using the c++ or
g++ complier in cygwin. My mangled code looks like this,
#include <iostream>
int main ()
{
cout << "Hello World";
return;
}
It looks like my example but it isn't working.
the compiler for g++ tells me the following:
hellotest.cpp: In function `int main()':
hellotest.cpp:5: error: `cout' undeclared (first use this function)
hellotest.cpp:5: error: (Each undeclared identifier is reported only once
for each function it appears in.)
hellotest.cpp:6: error: return-statement with no value, in function
returning 'int'
When I run it with an older complier Borland 4.5 it tells me that it can't
read the input file helloworld.rc.
What am I doing wrong?
|
|
| Back to top |
|
 |
roberts.noah@gmail.com Guest
|
Posted: Wed Jan 18, 2006 3:57 pm Post subject: Re: stoopid begineer with a question |
|
|
knilges wrote:
| Quote: | I am trying to build a Hello World program in C++. I am using the c++ or
g++ complier in cygwin. My mangled code looks like this,
#include
int main ()
{
cout << "Hello World";
return;
}
|
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
| Quote: |
It looks like my example but it isn't working.
the compiler for g++ tells me the following:
hellotest.cpp: In function `int main()':
hellotest.cpp:5: error: `cout' undeclared (first use this function)
hellotest.cpp:5: error: (Each undeclared identifier is reported only once
for each function it appears in.)
hellotest.cpp:6: error: return-statement with no value, in function
returning 'int'
When I run it with an older complier Borland 4.5 it tells me that it can't
read the input file helloworld.rc.
|
That is some sort of compiler dependent file.
| Quote: |
What am I doing wrong?
|
|
|
| Back to top |
|
 |
Thomas Tutone Guest
|
Posted: Wed Jan 18, 2006 3:59 pm Post subject: Re: stoopid begineer with a question |
|
|
knilges wrote:
| Quote: | I am trying to build a Hello World program in C++. I am using the c++ or
g++ complier in cygwin. My mangled code looks like this,
#include
int main ()
{
cout << "Hello World";
|
replace the above line with:
std::cout << "Hello World";
and your program will compile fine.
Delete the above line entirely, or replace it with:
return 0;
Best regards,
Tom
|
|
| Back to top |
|
 |
Mike Smith Guest
|
Posted: Wed Jan 18, 2006 4:32 pm Post subject: Re: stoopid begineer with a question |
|
|
[email]roberts.noah (AT) gmail (DOT) com[/email] wrote:
| Quote: | knilges wrote:
I am trying to build a Hello World program in C++. I am using the c++ or
g++ complier in cygwin. My mangled code looks like this,
#include
int main ()
{
cout << "Hello World";
return;
}
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
|
Or just leave out the return - a main() with no return is assumed to
return EXIT_SUCCESS.
--
Mike Smith
|
|
| Back to top |
|
 |
David Harmon Guest
|
Posted: Wed Jan 18, 2006 5:42 pm Post subject: Re: stoopid begineer with a question |
|
|
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
[email]roberts.noah (AT) gmail (DOT) com[/email] wrote,
| Quote: | std::cout << "Hello World" << std::endl;
|
endl is uncalled for there. Please don't teach bad habits.
If you want to add a newline, it should be:
std::cout << "Hello Worldn";
|
|
| Back to top |
|
 |
roberts.noah@gmail.com Guest
|
Posted: Wed Jan 18, 2006 6:20 pm Post subject: Re: stoopid begineer with a question |
|
|
David Harmon wrote:
| Quote: | On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
[email]roberts.noah (AT) gmail (DOT) com[/email] wrote,
std::cout << "Hello World" << std::endl;
endl is uncalled for there. Please don't teach bad habits.
If you want to add a newline, it should be:
std::cout << "Hello Worldn";
|
Since std::cout may very well be buffered it is actually prudent to
pass std::endl instead of 'n'. In this *particular* case, since the
program exits immediately following the operation it is "unneccisary"
but it is a GOOD habit to get into since in anything more complex than
a hello world program is going to do more and you should flush your
outputs when you want them to be sent.
So, to each his own. I'll answer questions the way I see fit and
people can learn, or not, what they want.
Thanks anyway.
|
|
| Back to top |
|
 |
Mike Wahler Guest
|
Posted: Wed Jan 18, 2006 6:45 pm Post subject: Re: stoopid begineer with a question |
|
|
<roberts.noah (AT) gmail (DOT) com> wrote
| Quote: |
David Harmon wrote:
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
[email]roberts.noah (AT) gmail (DOT) com[/email] wrote,
std::cout << "Hello World" << std::endl;
endl is uncalled for there. Please don't teach bad habits.
If you want to add a newline, it should be:
std::cout << "Hello Worldn";
Since std::cout may very well be buffered it is actually prudent to
pass std::endl instead of 'n'. In this *particular* case, since the
program exits immediately following the operation it is "unneccisary"
but it is a GOOD habit
|
IMO a 'good' habit would be something that is
always 'good' in general (e.g. use consistent
indentation style). But imo 'proper' use of
'endl' depends much upon context. Because of
what it does, using it needlessly can unnecessarily
degrade performance. (i/o is typically the slowest
part of a system -- that's why buffering was invented).
| Quote: | to get into since in anything more complex than
a hello world program is going to do more and you should flush your
outputs when you want them to be sent.
|
But it's often the case that 'visible' output is not needed
at every occurence of 'n'.
| Quote: | So, to each his own. I'll answer questions the way I see fit and
people can learn, or not, what they want.
|
And others will insert their opinions as they see fit. :-)
FWIW I've still never had the need to use 'endl' with
output streams.
-Mike
|
|
| Back to top |
|
 |
roberts.noah@gmail.com Guest
|
Posted: Wed Jan 18, 2006 6:51 pm Post subject: Re: stoopid begineer with a question |
|
|
Mike Wahler wrote:
| Quote: | roberts.noah (AT) gmail (DOT) com> wrote in message
news:1137608448.846583.265250 (AT) g14g2000cwa (DOT) googlegroups.com...
David Harmon wrote:
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
[email]roberts.noah (AT) gmail (DOT) com[/email] wrote,
std::cout << "Hello World" << std::endl;
endl is uncalled for there. Please don't teach bad habits.
So, to each his own. I'll answer questions the way I see fit and
people can learn, or not, what they want.
And others will insert their opinions as they see fit.
|
Well it seems some people feel I need permission to do so.
|
|
| Back to top |
|
 |
roberts.noah@gmail.com Guest
|
Posted: Wed Jan 18, 2006 6:52 pm Post subject: Re: stoopid begineer with a question |
|
|
Mike Wahler wrote:
| Quote: | roberts.noah (AT) gmail (DOT) com> wrote in message
news:1137608448.846583.265250 (AT) g14g2000cwa (DOT) googlegroups.com...
David Harmon wrote:
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
[email]roberts.noah (AT) gmail (DOT) com[/email] wrote,
std::cout << "Hello World" << std::endl;
endl is uncalled for there. Please don't teach bad habits.
So, to each his own. I'll answer questions the way I see fit and
people can learn, or not, what they want.
And others will insert their opinions as they see fit.
|
Well it seems some people feel I need permission to do so.
|
|
| Back to top |
|
 |
Mike Wahler Guest
|
Posted: Wed Jan 18, 2006 11:29 pm Post subject: Re: stoopid begineer with a question |
|
|
<roberts.noah (AT) gmail (DOT) com> wrote
| Quote: |
Mike Wahler wrote:
[email]roberts.noah (AT) gmail (DOT) com[/email]> wrote in message
news:1137608448.846583.265250 (AT) g14g2000cwa (DOT) googlegroups.com...
David Harmon wrote:
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
[email]roberts.noah (AT) gmail (DOT) com[/email] wrote,
std::cout << "Hello World" << std::endl;
endl is uncalled for there. Please don't teach bad habits.
So, to each his own. I'll answer questions the way I see fit and
people can learn, or not, what they want.
And others will insert their opinions as they see fit. :-)
Well it seems some people feel I need permission to do so.
|
Really? I haven't seen any indication of that. If someone
responds to your post with e.g. "don't say that", that simply
means they disagree, not that they're demanding you ask permission
to say it. (Civilly expressed) disagreements often lead to
useful discussion. Discussion sheds light on both sides of an
issue, and allows observers to draw their own conclusions.
I think that is especially useful for the novice.
-Mike
|
|
| Back to top |
|
 |
knilges Guest
|
Posted: Thu Jan 19, 2006 2:08 am Post subject: Re: stoopid begineer with a question |
|
|
You guys must drink a lot of coffee!!! Whoa! LOL!
"Mike Wahler" <mkwahler (AT) mkwahler (DOT) net> wrote
| Quote: | roberts.noah (AT) gmail (DOT) com> wrote in message
news:1137610321.710877.315490 (AT) g49g2000cwa (DOT) googlegroups.com...
Mike Wahler wrote:
[email]roberts.noah (AT) gmail (DOT) com[/email]> wrote in message
news:1137608448.846583.265250 (AT) g14g2000cwa (DOT) googlegroups.com...
David Harmon wrote:
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
[email]roberts.noah (AT) gmail (DOT) com[/email] wrote,
std::cout << "Hello World" << std::endl;
endl is uncalled for there. Please don't teach bad habits.
So, to each his own. I'll answer questions the way I see fit and
people can learn, or not, what they want.
And others will insert their opinions as they see fit. :-)
Well it seems some people feel I need permission to do so.
Really? I haven't seen any indication of that. If someone
responds to your post with e.g. "don't say that", that simply
means they disagree, not that they're demanding you ask permission
to say it. (Civilly expressed) disagreements often lead to
useful discussion. Discussion sheds light on both sides of an
issue, and allows observers to draw their own conclusions.
I think that is especially useful for the novice.
-Mike
|
|
|
| Back to top |
|
 |
Geo Guest
|
Posted: Fri Jan 27, 2006 10:12 am Post subject: Re: stoopid begineer with a question |
|
|
adrian suri wrote:
| Quote: | hi
Hi
try this instead, you missed out the name space declaration
//hello.cpp
#include
using namespace std;
|
Argh... no don't do this
see the FAQ
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5
| Quote: | int main ()
{
cout << "Hello World" <
return 0;
}
compiles fine under watcom 1.4 under OS/2 4.52
regards
Adrian
knilges wrote:
I am trying to build a Hello World program in C++. I am using the c++ or
g++ complier in cygwin. My mangled code looks like this,
#include
int main ()
{
cout << "Hello World";
return;
}
It looks like my example but it isn't working.
the compiler for g++ tells me the following:
hellotest.cpp: In function `int main()':
hellotest.cpp:5: error: `cout' undeclared (first use this function)
hellotest.cpp:5: error: (Each undeclared identifier is reported only once
for each function it appears in.)
hellotest.cpp:6: error: return-statement with no value, in function
returning 'int'
When I run it with an older complier Borland 4.5 it tells me that it can't
read the input file helloworld.rc.
What am I doing wrong?
|
|
|
| Back to top |
|
 |
Daniel T. Guest
|
Posted: Fri Jan 27, 2006 12:34 pm Post subject: Re: stoopid begineer with a question |
|
|
In article <1138356771.902259.232600 (AT) g44g2000cwa (DOT) googlegroups.com>,
"Geo" <gg (AT) remm (DOT) org> wrote:
As I recall, Herb Sutter disagrees with the faq on this point.
|
|
| Back to top |
|
 |
Geo Guest
|
Posted: Fri Jan 27, 2006 12:42 pm Post subject: Re: stoopid begineer with a question |
|
|
Daniel T. wrote:
| Quote: | In article <1138356771.902259.232600 (AT) g44g2000cwa (DOT) googlegroups.com>,
"Geo" <gg (AT) remm (DOT) org> wrote:
try this instead, you missed out the name space declaration
//hello.cpp
#include
using namespace std;
Argh... no don't do this
see the FAQ
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5
As I recall, Herb Sutter disagrees with the faq on this point.
|
Well that's Herb's choice, but I think I'll go with the concensus
opinion of he FAQ on this one YMMV.
|
|
| Back to top |
|
 |
Gavin Deane Guest
|
Posted: Fri Jan 27, 2006 2:37 pm Post subject: Re: stoopid begineer with a question |
|
|
Daniel T. wrote:
| Quote: | In article <1138356771.902259.232600 (AT) g44g2000cwa (DOT) googlegroups.com>,
"Geo" <gg (AT) remm (DOT) org> wrote:
try this instead, you missed out the name space declaration
//hello.cpp
#include
using namespace std;
Argh... no don't do this
see the FAQ
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5
As I recall, Herb Sutter disagrees with the faq on this point.
|
Can you cite any reference for that? An online source or a book? I'd be
quite surprised to see Herb Sutter generally recommending using
directives (as opposed to using declarations). If he does disagree with
the FAQ I would be interested to read about it.
Gavin Deane
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|