stoopid begineer with a question

Discussion in 'C++' started by knilges, Jan 18, 2006.

  1. knilges

    knilges Guest

    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?
     
    knilges, Jan 18, 2006
    #1
    1. Advertising

  2. knilges

    Guest

    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, 2006
    #2
    1. Advertising

  3. 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
     
    Thomas Tutone, Jan 18, 2006
    #3
  4. knilges

    Mike Smith Guest

    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
     
    Mike Smith, Jan 18, 2006
    #4
  5. knilges

    David Harmon Guest

    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";
     
    David Harmon, Jan 18, 2006
    #5
  6. knilges

    Guest

    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.
     
    , Jan 18, 2006
    #6
  7. knilges

    Mike Wahler Guest

    <> wrote in message
    news:...
    >
    > 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
     
    Mike Wahler, Jan 18, 2006
    #7
  8. knilges

    Guest

    Mike Wahler wrote:
    > <> wrote in message
    > news:...
    > >
    > > 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.
     
    , Jan 18, 2006
    #8
  9. knilges

    Guest

    Mike Wahler wrote:
    > <> wrote in message
    > news:...
    > >
    > > 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.
     
    , Jan 18, 2006
    #9
  10. knilges

    Mike Wahler Guest

    <> wrote in message
    news:...
    >
    > Mike Wahler wrote:
    >> <> wrote in message
    >> news:...
    >> >
    >> > 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
     
    Mike Wahler, Jan 18, 2006
    #10
  11. knilges

    knilges Guest

    You guys must drink a lot of coffee!!! Whoa! LOL!




    "Mike Wahler" <> wrote in message
    news:gbAzf.6516$...
    > <> wrote in message
    > news:...
    >>
    >> Mike Wahler wrote:
    >>> <> wrote in message
    >>> news:...
    >>> >
    >>> > 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
    >
    >
     
    knilges, Jan 19, 2006
    #11
  12. knilges

    adrian suri Guest

    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?
    >
    >
     
    adrian suri, Jan 26, 2006
    #12
  13. knilges

    adrian suri Guest

    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?
    >
    >
     
    adrian suri, Jan 26, 2006
    #13
  14. knilges

    Geo Guest

    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-lite/coding-standards.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?
    > >
    > >
     
    Geo, Jan 27, 2006
    #14
  15. knilges

    Daniel T. Guest

    In article <>,
    "Geo" <> 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-lite/coding-standards.html#faq-27.5


    As I recall, Herb Sutter disagrees with the faq on this point.
     
    Daniel T., Jan 27, 2006
    #15
  16. knilges

    Geo Guest

    Daniel T. wrote:
    > In article <>,
    > "Geo" <> 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-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.
     
    Geo, Jan 27, 2006
    #16
  17. knilges

    Gavin Deane Guest

    Daniel T. wrote:
    > In article <>,
    > "Geo" <> 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-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
     
    Gavin Deane, Jan 27, 2006
    #17
  18. knilges

    Daniel T. Guest

    In article <>,
    "Gavin Deane" <> wrote:

    > Daniel T. wrote:
    > > In article <>,
    > > "Geo" <> 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-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?


    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>
     
    Daniel T., Jan 27, 2006
    #18
  19. knilges

    Gavin Deane Guest

    Daniel T. wrote:
    > In article <>,
    > "Gavin Deane" <> wrote:
    >
    > > Daniel T. wrote:
    > > > In article <>,
    > > > "Geo" <> wrote:
    > > > > 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?

    >
    > 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
     
    Gavin Deane, Jan 27, 2006
    #19
  20. knilges

    WToma Guest

    Do you know how many gourp members does it take to change a light bulb?
    :)
    Nice day :)
    Toma
     
    WToma, Jan 27, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    614
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    682
    Iain Norman
    Feb 16, 2005
  3. peter leonard
    Replies:
    0
    Views:
    312
    peter leonard
    Sep 22, 2003
  4. begineer

    , Jul 8, 2007, in forum: C++
    Replies:
    21
    Views:
    1,026
    tanmay
    Jul 10, 2007
  5. jim o

    Begineer question

    jim o, May 18, 2007, in forum: Ruby
    Replies:
    8
    Views:
    200
    Robert Dober
    May 20, 2007
Loading...

Share This Page