Find the answer to your Linux question:
Results 1 to 9 of 9
Hi, all I have just recently started to program in C++, but there seems to be a continuous problem. I have written the code exactly as the guide says, and ...
  1. #1
    Just Joined!
    Join Date
    May 2009
    Location
    New South Whales, Australia
    Posts
    30

    Question C++ Error

    Hi, all

    I have just recently started to program in C++, but there seems to be a continuous problem.

    I have written the code exactly as the guide says, and it compiles fine, but it says that the execution is terminated.

    Can anyone help me?

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Could we see the code..
    Make mine Arch Linux

  3. #3
    Just Joined!
    Join Date
    May 2009
    Location
    New South Whales, Australia
    Posts
    30
    // my first program in C++

    #include <iostream>
    using namespace std;

    int main () {
    cout << "Hello World!";
    return 0;
    }

  4. #4
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Just tried your code an it ran fine

    compile line:
    g++ filename.cpp -o filename
    then executed with

    ./filename
    Make mine Arch Linux

  5. #5
    Just Joined!
    Join Date
    Feb 2010
    Posts
    2
    I think you should use getch() or system("pause")
    Try this
    // my first program in C++

    #include <iostream>
    using namespace std;

    int main () {
    cout << "Hello World!";
    system("pause");
    return 0;
    }

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Well, it should work, but you are missing an endl output manipulator so your "Hello World!" string will get output before you die. Ie,
    Code:
    // my first program in C++
    
    #include <iostream>
    using namespace std;
    
    int main (void) {
    cout << "Hello World!" << endl;
    return 0;
    }
    Also note the (void) argument list for main(). This is necessary for many current ANSI-compliant C++ compilers.

    BTW, we are not supposed to help you with school work. If this is just self-learning, then it's ok, but do respect the terms of use for the forums.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    BTW, the std::endl manipulator also inserts a newline in the stream.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #8
    Just Joined!
    Join Date
    May 2009
    Location
    New South Whales, Australia
    Posts
    30
    Thanks for the help, and BTW, I finished school last year, so it's not school work

  9. #9
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by caboose View Post
    Thanks for the help, and BTW, I finished school last year, so it's not school work
    I thought something like that might be the case, which is why I didn't bring up the schoolwork thing until after I responded to your question. Now, did that help fix your problem?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...