473,325 Members | 2,442 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,325 software developers and data experts.

hello world program

Hi guys,
I'm trying to run small program helloworld.cpp.
But i'm not getting any output on the stdout

program is
#include<iostream.h>
main(){
cout<<"hello world";
}
>>>>>>>>>>>>>>>>>>>>>>

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

I have compiled the program with g++
g++ helloworld.cpp -o helloworld
../helloworld

It does prints hello world on stdout

compiler I'm using is
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
Jul 19 '05 #1
15 15369
On Thu, 28 Aug 2003 23:04:03 -0700, Rahul Gandhi wrote:
Hi guys,
I'm trying to run small program helloworld.cpp.
But i'm not getting any output on the stdout

program is
#include<iostream.h>
main(){
cout<<"hello world";
}
>>>>>>>>>>>>>>>>>>>>>>>

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

I have compiled the program with g++
g++ helloworld.cpp -o helloworld
./helloworld

It does prints hello world on stdout

compiler I'm using is
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)


I am using
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
and both versions compile and print to stdout, although the first gives a
warning ,iostream.h seems to be "antiquated".
Maybe You just overlooked it, because its in front of the next prompt.
Insert \n after world.

--
mfg
Volker Mosthaf
Jul 19 '05 #2
"Jim Fischer" <jf***************@now.here.com> wrote in message
news:01*****************@fe01.atl2.webusenet.com.. .
| I don't know if this is the problem or not, but try flushing the output
| stream 'cout' before the program ends:

Yes, this is most likely the problem. You should also make main() int main()
and return 0 at the end (before closing brace):

#include <iostream>

int main()
{
std::cout << "Hello Rahul Gandhi!" << std::flush;
return(0);
}
Jul 19 '05 #3
Greg P. wrote:
"Jim Fischer" <jf***************@now.here.com> wrote in message
news:01*****************@fe01.atl2.webusenet.com.. .
I don't know if this is the problem or not, but try flushing the
output stream 'cout' before the program ends:
Yes, this is most likely the problem. You should also make main() int
main() and return 0 at the end (before closing brace):

#include <iostream>

int main()
{
std::cout << "Hello Rahul Gandhi!" << std::flush;


This may still not work, there is no newline. You may flush it but
displaying is only guaranteed for lines. So the game is:

std::cout << "Hello Rahul Gandhi!" << std::endl;

std::endl sends a newline to the buffer and then make sure it is written
(does an std::flush).
return(0);
No need for that. And even if you write it there is absolutely no need for
the parentheses around the 0.
}


--
Attila aka WW
Jul 19 '05 #4
Greg P. wrote:
"Jim Fischer" <jf***************@now.here.com> wrote in message
news:01*****************@fe01.atl2.webusenet.com.. .
| I don't know if this is the problem or not, but try flushing the output
| stream 'cout' before the program ends:

Yes, this is most likely the problem. You should also make main() int main()
and return 0 at the end (before closing brace):
I thought the C++ standard said we don't have to bother returning 0 at
the end, as it is done automatically?


#include <iostream>

int main()
{
std::cout << "Hello Rahul Gandhi!" << std::flush;
return(0);
}


It is (arguably) better to write return 0;, to make it clear that return
isn't a function but something special.

Jul 19 '05 #5
"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bi**********@newstree.wise.edt.ericsson.se...
| > return(0);
|
| No need for that. And even if you write it there is absolutely no need
for
| the parentheses around the 0.

If the OP is new to C++ (as I assume from his post), then it is good
practice to start "return"ing. Yes it's true that it is not needed (as it
automatically does this at the end of main's scope). But returning a status
now will allow the OP to keep it in mind when it comes time to return during
an error condition.

Oh, and all my colleagues hassle me about my parenthesis. I was taught this
early on by some old farts and it has since stuck to me. There is no harm,
and it's purely a stylistic view. The same argument could be said about K&R
coding style (which I have barely just got un-accustomed to). Please don't
badger me on my style =)
Jul 19 '05 #6
Greg P. wrote:
"chris" <ch***@bubblescope.net> wrote in message
news:bi**********@pump1.york.ac.uk...
I thought the C++ standard said we don't have to bother returning 0
at the end, as it is done automatically?


Correct.
It is (arguably) better to write return 0;, to make it clear that
return isn't a function but something special.


Well certain people look at it differently as they do art pieces. I
agree that if someone is new and returns with parenthesis it may
confuse them. Please read the reply I gave to Atilla above for my
comments on this.


If we really want to confuse them we can write return EXIT_SUCCESS. ;-)

--
Attila aka WW
Jul 19 '05 #7
Greg P. wrote:
"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bi**********@newstree.wise.edt.ericsson.se...
return(0);


No need for that. And even if you write it there is absolutely no
need for the parentheses around the 0.


If the OP is new to C++ (as I assume from his post), then it is good
practice to start "return"ing. Yes it's true that it is not needed
(as it automatically does this at the end of main's scope). But
returning a status now will allow the OP to keep it in mind when it
comes time to return during an error condition.

Oh, and all my colleagues hassle me about my parenthesis. I was
taught this early on by some old farts and it has since stuck to me.
There is no harm, and it's purely a stylistic view. The same argument
could be said about K&R coding style (which I have barely just got
un-accustomed to). Please don't badger me on my style =)


All my point was (no badgering! :-) ) is that if you show this to a newbie
he might think that the parenthesis are required and that return in main,
too. My point is rather that IMHO it is preferable to give that little
speach about "it is not mandatory to return but it is a good style to do so,
because...". Well, I dunno any good excuses for the parentheses. ;-)

--
Attila aka WW
Jul 19 '05 #8
<chris>
I thought the C++ standard said we don't have to bother returning 0 at
the end, as it is done automatically?
</chris>

What confuses me is this:

int f(){}
int main(int,char**){int a=f();}

This compiles (with a warning).
It looks like an error to me. And
what is the value of 'a' after this?

-X

Jul 19 '05 #9
> <chris>
I thought the C++ standard said we don't have to bother returning 0 at
the end, as it is done automatically?
</chris>

What confuses me is this:

int f(){}
int main(int,char**){int a=f();}

This compiles (with a warning).
It looks like an error to me. And
what is the value of 'a' after this?


main() is a special case and returns 0 if you don't explicitly do a
return yourself (one popular compiler doesn't accept this however). As
far as the f() function is concerned, I don't think that it should
compile and you might be looking at a compiler bug (I didn't look it up
in the standard so I might be wrong).

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Jul 19 '05 #10
Peter van Merkerk wrote:
[SNIP-SNAP]
main() is a special case and returns 0 if you don't explicitly do a
return yourself (one popular compiler doesn't accept this however). As
far as the f() function is concerned, I don't think that it should
compile and you might be looking at a compiler bug (I didn't look it
up in the standard so I might be wrong).


Unfortunately those bugs exist, especially if there is a complex branching
inside with return statement. Some compilers just miss those branches where
there is no return. Some others go to the other extreme:

bool func( some args) {
if (using args) {
DoSomething();
return true;
} else {
DoSomethingElse();
return false;
}
}

and you get an error that there is no return... Of course it is simple in
this case: just remove the else and there ya go. ;-)

--
Attila aka WW
Jul 19 '05 #11
Attila Feher wrote:
Greg P. wrote:
"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bi**********@newstree.wise.edt.ericsson.se. ..
return(0);

No need for that. And even if you write it there is absolutely no
need for the parentheses around the 0.
..... Well, I dunno any good excuses for the parentheses. ;-)


Don't want to encourage too many parentheses, else people might mistake
your code for lisp :)

Jul 19 '05 #12
chris wrote:
Attila Feher wrote:
Greg P. wrote:
"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bi**********@newstree.wise.edt.ericsson.se...

> return(0);

No need for that. And even if you write it there is absolutely no
need for the parentheses around the 0. .... >> Well, I dunno any good excuses for the parentheses. ;-)


Don't want to encourage too many parentheses, else people might
mistake your code for lisp :)


They reminded me of lips. Time to get a girlfriend again. :-)

--
WW aka Attila
Jul 19 '05 #13
"Agent Mulder" <mb*******************@home.nl> wrote in message
news:bi**********@news2.tilbu1.nb.home.nl...

What confuses me is this:

int f(){}
int main(int,char**){int a=f();}

This compiles (with a warning).
It looks like an error to me. And
what is the value of 'a' after this?


From the standard, 6.3.3:
"Flowing off the end of a function is equivalent to a return
with no value; this results in undefined behavior in a value
returning function."

[main(), as we know, is an exception]

Jul 19 '05 #14
Volker Mosthaf wrote:
Maybe You just overlooked it, because its in front of the next prompt.
Insert \n after world.


Some shells will completely overwrite the last "line" of output if it's
not properly terminated, I think. I also believe that ending output with
a newline is required by the standard.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #15
"White Wolf" <wo***@freemail.hu> wrote in message
news:bi**********@phys-news1.kolumbus.fi...
<snip>
lol! You are all right. I have never looked at my returns in that light. I
guess it's time for me to "re-adjust" my coding style if I plan to be
helping the rookies out there =)
Jul 19 '05 #16

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

Similar topics

3
by: penguinman | last post by:
Its just a hello world program. Compile and build goes with no warning or error. i type ./a.out and the shell just sits there. It doesnt hang but it just sits there with no output. I executed...
9
by: PG | last post by:
Hi gurus, I have AIX visual age C++ compiler version 5.0.2.3. I have a simple hello world program that gives compilation errors. Any help will be appreciated. Thanks PG ***test.cpp**** ...
33
by: ankursinha | last post by:
Hi, Is it possible to write a C program that prints "Hello World" on screen without having a single semi-colon in the entire program? The extra constraint here is that u r not allowed to use...
42
by: Prashanth Badabagni | last post by:
Hi, Can any body tell me how to print "hello,world" with out using semicolon Thanks in advance .. Bye Prashanth Badabagni
26
by: Santanu Chatterjee | last post by:
Hello all, I would like to know how an OS makes a computer boot up. For that, as a start I would like to see an e_ample (read the underscore as the letter before y, as the keyboard here is...
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
1
by: Tarique Jawed | last post by:
Alright - I've been using VS .NET for all of 3 hours now - so pardon the stupidity of my question. Can someone walk me through a simple hello world that outputs to console, in terms of which...
2
by: Sourcerer | last post by:
I'm making a "hello world" program in C#, though a bit more complex one. When I click on a button in my program, it is supposed to open a program (say, Notepad) - that I did, by opening Notepad...
1
by: James T. Dennis | last post by:
You'd think that using things like gettext would be easy. Superficially it seems well documented in the Library Reference(*). However, it can be surprisingly difficult to get the external details...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.