Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > stoopid begineer with a question

Reply
Thread Tools

stoopid begineer with a question

 
 
knilges
Guest
Posts: n/a
 
      01-18-2006
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?


 
Reply With Quote
 
 
 
 
roberts.noah@gmail.com
Guest
Posts: n/a
 
      01-18-2006

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 <iostream>
>
> int main ()
> {
> cout << "Hello World";
> return;
> }


int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
>
> 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.
>
> What am I doing wrong?


 
Reply With Quote
 
 
 
 
Thomas Tutone
Guest
Posts: n/a
 
      01-18-2006
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 <iostream>
>
> int main ()
> {
> cout << "Hello World";


replace the above line with:

std::cout << "Hello World";

and your program will compile fine.

> return;


Delete the above line entirely, or replace it with:

return 0;

> }
>


Best regards,

Tom

 
Reply With Quote
 
Mike Smith
Guest
Posts: n/a
 
      01-18-2006
wrote:
> 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 <iostream>
>>
>> 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
 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      01-18-2006
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
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 World\n";

 
Reply With Quote
 
roberts.noah@gmail.com
Guest
Posts: n/a
 
      01-18-2006

David Harmon wrote:
> On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
> 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 World\n";


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.

 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-18-2006
<> wrote in message
news: oups.com...
>
> David Harmon wrote:
>> On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
>> 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 World\n";

>
> 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).

> 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'.


> 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


 
Reply With Quote
 
roberts.noah@gmail.com
Guest
Posts: n/a
 
      01-18-2006

Mike Wahler wrote:
> <> wrote in message
> news: oups.com...
> >
> > David Harmon wrote:
> >> On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
> >> 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.

 
Reply With Quote
 
roberts.noah@gmail.com
Guest
Posts: n/a
 
      01-18-2006

Mike Wahler wrote:
> <> wrote in message
> news: oups.com...
> >
> > David Harmon wrote:
> >> On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
> >> 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.

 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-18-2006
<> wrote in message
news: oups.com...
>
> Mike Wahler wrote:
>> <> wrote in message
>> news: oups.com...
>> >
>> > David Harmon wrote:
>> >> On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
>> >> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Begineer help needed Jaskaranbir MCSD 0 12-28-2007 10:14 PM
begineer 10may.agn03@gmail.com C++ 21 07-10-2007 10:39 AM
Begineer question jim o Ruby 8 05-20-2007 06:06 PM
A begineer need advice =?Utf-8?B?UmFnZ29vaQ==?= Microsoft Certification 3 11-15-2005 10:02 PM
Begineer Question : Global string substitution with re peter leonard Python 0 09-22-2003 09:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57