1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

"Hello world" won't compile in gcc

Discussion in 'Computer Talk' started by aneeshm, Jun 29, 2004.

  1. aneeshm

    aneeshm Deity

    Joined:
    Aug 26, 2001
    Messages:
    6,666
    Location:
    Mountain View, California, USA
    I'm currently using gcc on RHEL WS v3(Taroon) , and I can't get it to work compile Hello World" .

    The program follows .

    #include<iostream>

    using namespace std;

    int main()
    {
    cout<<"\nHello World";
    }


    GCC outputs :

    In function int main
    undefined reference to cout
    Use the function first

    or something similar .

    Any help ?
     
  2. ainwood

    ainwood Consultant. Administrator

    Joined:
    Oct 5, 2001
    Messages:
    30,068
    I'm no C programmer, (and I'm sure one who actually knows what (s)he's talking about will come by shortly, but don't you need a return value (eg return 0)

    Also, try some spaces between the characters.
     
  3. aneeshm

    aneeshm Deity

    Joined:
    Aug 26, 2001
    Messages:
    6,666
    Location:
    Mountain View, California, USA
    I'll try returning . Anything else ?
     
  4. kcwong

    kcwong Emperor

    Joined:
    Jan 31, 2002
    Messages:
    1,108
    Location:
    Hong Kong
    The compiler said it doesn't know what is "cout".

    You can't use C++ stuff just like that with gcc - it's for compiling C, not C++. If you want to stick with C++, use another compiler - e.g. g++.

    Or you can simply change the code and use stdio.h and printf instead.

    Google groups search for "cout gcc" for more information.
     
  5. Comraddict

    Comraddict C.IV

    Joined:
    Aug 2, 2003
    Messages:
    1,702
    Location:
    Iowa
    ..and isn't "\n" supposed to go after hello world?

    also it is iostream.h not iostream
     
  6. nihilistic

    nihilistic Intergalatic Delivery Boy

    Joined:
    Feb 24, 2003
    Messages:
    3,261
    Location:
    NNYC
    #include<stdio.h>

    int main()
    {
    printf("\nHello World!\n");
    return 0;
    }


    // Most Modern compilers will also accept

    #include<stdio.h>
    void main(){printf("\nHello World!\n");}
     
  7. GenghisK

    GenghisK ...

    Joined:
    Mar 13, 2001
    Messages:
    4,121
    Location:
    Far from the 2 idiot posters in FPT
    IMHO, cout would require the library called conio.h (console i/o)
    Actually I always automatically put conio et stdio since they are almost always required.
     

Share This Page