473,385 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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?
Jan 18 '06 #1
24 1785

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?


Jan 18 '06 #2
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

Jan 18 '06 #3
ro**********@gmail.com 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
Jan 18 '06 #4
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
ro**********@gmail.com 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";

Jan 18 '06 #5

David Harmon wrote:
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
ro**********@gmail.com 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.

Jan 18 '06 #6
<ro**********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

David Harmon wrote:
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
ro**********@gmail.com 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
Jan 18 '06 #7

Mike Wahler wrote:
<ro**********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

David Harmon wrote:
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
ro**********@gmail.com 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.

Jan 18 '06 #8

Mike Wahler wrote:
<ro**********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

David Harmon wrote:
On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
ro**********@gmail.com 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.

Jan 18 '06 #9
<ro**********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

Mike Wahler wrote:
<ro**********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
>
> David Harmon wrote:
>> On 18 Jan 2006 07:57:58 -0800 in comp.lang.c++,
>> ro**********@gmail.com 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
Jan 18 '06 #10
You guys must drink a lot of coffee!!! Whoa! LOL!


"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:gb****************@newsread2.news.pas.earthli nk.net...
<ro**********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

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

Jan 19 '06 #11
Hi

try this instead, you missed out the name space declaration
//hello.cpp

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

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 <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?

Jan 26 '06 #12

hi

Hi

try this instead, you missed out the name space declaration
//hello.cpp

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

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 <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?

Jan 26 '06 #13
Geo
adrian suri wrote:
hi

Hi

try this instead, you missed out the name space declaration
//hello.cpp

#include <iostream>
using namespace std;
Argh... no don't do this

see the FAQ

http://www.parashift.com/c++-faq-lit....html#faq-27.5
int main ()
{
cout << "Hello World" <<endl;

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 <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?


Jan 27 '06 #14
In article <11**********************@g44g2000cwa.googlegroups .com>,
"Geo" <gg@remm.org> wrote:
try this instead, you missed out the name space declaration
//hello.cpp

#include <iostream>
using namespace std;


Argh... no don't do this

see the FAQ

http://www.parashift.com/c++-faq-lit....html#faq-27.5


As I recall, Herb Sutter disagrees with the faq on this point.
Jan 27 '06 #15
Geo

Daniel T. wrote:
In article <11**********************@g44g2000cwa.googlegroups .com>,
"Geo" <gg@remm.org> wrote:
try this instead, you missed out the name space declaration
//hello.cpp

#include <iostream>
using namespace std;


Argh... no don't do this

see the FAQ

http://www.parashift.com/c++-faq-lit....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.

Jan 27 '06 #16

Daniel T. wrote:
In article <11**********************@g44g2000cwa.googlegroups .com>,
"Geo" <gg@remm.org> wrote:
try this instead, you missed out the name space declaration
//hello.cpp

#include <iostream>
using namespace std;


Argh... no don't do this

see the FAQ

http://www.parashift.com/c++-faq-lit....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

Jan 27 '06 #17
In article <11**********************@z14g2000cwz.googlegroups .com>,
"Gavin Deane" <de*********@hotmail.com> wrote:
Daniel T. wrote:
In article <11**********************@g44g2000cwa.googlegroups .com>,
"Geo" <gg@remm.org> wrote:
> try this instead, you missed out the name space declaration
> //hello.cpp
>
> #include <iostream>
> using namespace std;

Argh... no don't do this

see the FAQ

http://www.parashift.com/c++-faq-lit....html#faq-27.5
As I recall, Herb Sutter disagrees with the faq on this point.


Can you cite any reference for that?


C/C++ Users Journal April 2004 "Using Me"
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.


I thought he had it online, because he originally recommended not doing
it (just like he originally recommended using deque rather than vector
as the default container) then changed his mind.

[Looks some more...] I found it, look at message 15 of this thread:
<http://tinyurl.com/a79an>
Jan 27 '06 #18

Daniel T. wrote:
In article <11**********************@z14g2000cwz.googlegroups .com>,
"Gavin Deane" <de*********@hotmail.com> wrote:
Daniel T. wrote:
In article <11**********************@g44g2000cwa.googlegroups .com>,
"Geo" <gg@remm.org> wrote:
> http://www.parashift.com/c++-faq-lit....html#faq-27.5

As I recall, Herb Sutter disagrees with the faq on this point.


Can you cite any reference for that?


C/C++ Users Journal April 2004 "Using Me"
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.


I thought he had it online, because he originally recommended not doing
it (just like he originally recommended using deque rather than vector
as the default container) then changed his mind.

[Looks some more...] I found it, look at message 15 of this thread:
<http://tinyurl.com/a79an>


Thanks for digging that out.

I'm actually a little surprised at some of his original recommendations
(the one's where he's now changed his mind). I don't think I'd bother
with using declarations in toy programs. And if I was migrating a code
base with the help of using directives, I'm not sure I'd necessarily
bother replacing them with appropriate using declarations at the end of
the process.

His advice seems to boil down to "Use the tools the language provides
you to make your life easier". Makes sense to me, as long as you
understand the risks inherent in those tools as well.

Gavin Deane

Jan 27 '06 #19
Do you know how many gourp members does it take to change a light bulb?
:)
Nice day :)
Toma

Jan 27 '06 #20

WToma wrote:
Do you know how many gourp members does it take to change a light bulb?


That is a hardware issue and has nothing to do with C++. Certainly the
standard neither states, nor implies, anything about light bulbs. You
should ask your question in a group specific to your specific lighting
management system.

Jan 27 '06 #21
On 27 Jan 2006 09:31:24 -0800, ro**********@gmail.com wrote:

WToma wrote:
Do you know how many gourp members does it take to change a light bulb?


That is a hardware issue and has nothing to do with C++. Certainly the
standard neither states, nor implies, anything about light bulbs. You
should ask your question in a group specific to your specific lighting
management system.


YOU! [Moe voice] Why I oughtta'! Bwha! :-D
Um... Merry Christmas you bastard! <g>
[That's a little... um, just a little um... joke. sigh]

Admit it, right before you clicked on this when you saw my moniker,
just for a split second you thought, oh... :-D

"One night I walked home very late and fell asleep in somebody's
satellite dish. My dreams showed up on TVs all over the world."-sw
Jan 27 '06 #22
On 27 Jan 2006 02:12:51 -0800, "Geo" <gg@remm.org> wrote:
adrian suri wrote:
#include <iostream>
using namespace std;


Argh... no don't do this
see the FAQ
http://www.parashift.com/c++-faq-lit....html#faq-27.5


That would be for production code correct? Let's parse the real
meaning of the emulating monkey-sheep-speech designed to impress the
perceived Alpha Males.

Argh: You are a stupid fool and I am more superior than you. [While
the monkey-sheep looks back for approval and acceptance from the
perceived Alpha Males.]

Let's examine some code from the good Doctors site:
From Bjarne Stroustrup's C++ Style and Technique FAQ
http://public.research.att.com/~bs/bs_faq2.html

<quote>
How do I write this very simple program?
[small bit of verbage snipped]
#include<iostream>
#include<vector>
#include<algorithm>
>>> using namespace std; <<<<<<<<<<<<<<<<<<<<<<<<<<< int main()
{
vector<double> v;

double d;
while(cin>>d) v.push_back(d); // read elements
if (!cin.eof()) { // check if input
failed
cerr << "format error\n";
return 1; // error return
}

cout << "read " << v.size() << " elements\n";

reverse(v.begin(),v.end());
cout << "elements in reverse order:\n";
for (int i = 0; i<v.size(); ++i) cout << v[i] << '\n';

return 0; // success return
}
</quote>

And another:
<quote>
#include<iostream>
#include<string>>> using namespace std; <<<<<<<<<<<<<<<<<<<<<<<<<

int main()
{
cout << "Please enter a word:\n";

string s;
cin>>s;

cout << "You entered " << s << '\n';
}
</quote>

You'll find his usage of "using namespace std;" all through his
examples.

If it's good enough for the "founder/creator" then it's good enough
for... well I guess we're going to find out.

I think it's clear, in short *example* programs it should not be a
constant myopic language lawyer wannabe's dream to constantly,
snottily, constantly, pedantically, constantly, humorlessly,
constantly beat that dead horse to a pulp.

"The land that had nourished him and had borne him fruit
now turned against him and called him a fruit. Man, I hate
land like that." -- Jack Handey
Jan 27 '06 #23
WToma wrote:
Do you know how many gourp members does it take to change a light
bulb? :)

The ISO C++ standard does not define the gourp class, so we have no
idea what it's members might be.

Brian

Jan 27 '06 #24
REH

"Default User" <de***********@yahoo.com> wrote in message
news:43*************@individual.net...
WToma wrote:
Do you know how many gourp members does it take to change a light
bulb? :)

The ISO C++ standard does not define the gourp class, so we have no
idea what it's members might be.

Brian


Besides, we're software guys. We leave that up to the hardware engineers.

REH
Jan 27 '06 #25

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: peter leonard | last post by:
Hi, This is a basic question but I can't figure out what is wron - even after reading the documentation. I have a script that normalizes strings. One of the steps is to convert all fractions too...
3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
0
by: wASP | last post by:
I thought it was something relatively simple: ViewState = SomeObj; Then: SomeObj = ViewState; So, in my own code, I have this on the initial load:
3
by: Sueffel | last post by:
And here I thought I had a handle on things. Well, maybe not. Here's my scenerio, I have a form I need to reuse, so I thought, let's throw the sucker in a DLL. Well, running into a problem, I...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
2
by: nimbalkar | last post by:
I am the begineer of the .net i know the c,c++,vb please send me notes for the begineer how to and where to write the programme .
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.