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 ...
- 01-31-2010 #1Just Joined!
- Join Date
- May 2009
- Location
- New South Whales, Australia
- Posts
- 30
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?
- 01-31-2010 #2
Could we see the code..
Make mine Arch Linux
- 02-01-2010 #3Just 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;
}
- 02-01-2010 #4
Just tried your code an it ran fine
compile line:
then executed withg++ filename.cpp -o filename
./filenameMake mine Arch Linux
- 02-01-2010 #5Just 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;
}
- 02-01-2010 #6Linux Guru
- 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,
Also note the (void) argument list for main(). This is necessary for many current ANSI-compliant C++ compilers.Code:// my first program in C++ #include <iostream> using namespace std; int main (void) { cout << "Hello World!" << endl; return 0; }
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!
- 02-01-2010 #7Linux Guru
- 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!
- 02-01-2010 #8Just 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
- 02-02-2010 #9Linux Guru
- 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
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
