no output

This is a discussion on no output within the Linux Programming forums, part of the Platform Specific Boards category; i am new to Linux and c++. i am using the g++ compiler and have done the standard hello world ...

  1. #1
    asm
    asm is offline
    Registered User
    Join Date
    Jul 2003
    Posts
    7

    no output

    i am new to Linux and c++. i am using the g++ compiler and have done the standard hello world program but i am not getting the output , here is my code /*
    #include <iostream.h>

    int main ()
    {
    cout << "Hello World!\n";
    return 0;
    }
    */
    i am using the shell and get no reports of errors
    at the propmpt i type "g++ test.cpp -o test"
    am i right in thinking that the hello world should appear in the shell

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You have to run the program after you compile it.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    asm
    asm is offline
    Registered User
    Join Date
    Jul 2003
    Posts
    7
    ok thx for that, i actually thought i had already done that.
    i have bin at this now 4 about 2 days and i seem to be goin in
    circles. the book i am reading gives nowt away. i have searched the
    GNU site where there is lots of info but carnt find what i need to know
    can u help?

  4. #4
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Uh... You seem to have the whole thing commented out (nothing between the /* and the */ actually gets compiled). Remove those, then:

    $ g++ -o test test.cpp
    ... Output ... Whatever
    $ test
    Hello World!
    $
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  5. #5
    asm
    asm is offline
    Registered User
    Join Date
    Jul 2003
    Posts
    7
    thanks very much 4 that. i appreciate that these are
    simple commands but as i said i am new to both.
    having traded in my VB and Windoz for Linux and c/c++ .
    thx again.

  6. #6
    asm
    asm is offline
    Registered User
    Join Date
    Jul 2003
    Posts
    7
    if test is the name of a command will that alter the output
    as my text file is called "test.cpp"?

  7. #7
    asm
    asm is offline
    Registered User
    Join Date
    Jul 2003
    Posts
    7
    i commented the code out as i thought that is how u show the code on the site?

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You can leave your source file as test.cpp, just make the binary a different name:

    >>g++ -o mytest test.cpp
    then run ./mytest

    If you have two commands/programs with the same name residing in different directories, you're going to get confused when it doesn't produce the expect results. Steer clear of file names that are already in use
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    asm
    asm is offline
    Registered User
    Join Date
    Jul 2003
    Posts
    7
    ok Salem as u r prob already aware that worked
    but what is ". /". ? anyhow thx all 4 the prompt replies.

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>but what is ". /".
    It means to run the program that is located in the current directory.

    If you just specify the program name, the shell will search the directories in your path looking for an appropriately name program, the first one it finds, it will execute. Using ./progname ensures you execute the one in the current directory.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    Registered User
    Join Date
    Jan 2003
    Posts
    88
    Originally posted by Salem

    Just to add to this - the current directory is NOT normally in the search path (unlike microsoft operating systems).

    Whilst you can put the current directory into the search path, it is not recommended as it is a security hazard.
    it is for me (as non-root) with slackware 9...i guess ill remove it


    good advice

  12. #12
    asm
    asm is offline
    Registered User
    Join Date
    Jul 2003
    Posts
    7

    Thumbs up

    ok thx u have all been a big help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 03:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 06:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21