-
hello world, please help
Hey, I'm all new at this but I made my first "hello World" program. I wrote in the code and all the code is right, and i compiled it but when I try to open my program the Ms-DOS window pops up for like half a second then dissapears....after clicking real fast i can see that it says hello world in the window, but i can't keep it open!!
please help
[email protected]
-
be sure to include conio.h and before the 'return 0;' put getch();
-
#include <iostream>
#include <conio.h>
int main()
{
cout << "Hello World!!!";
getch();
return 0;
}
-
Code:
#include <iostream.h>
#include <conio.h>
int main()
{
//all your hello world stuff
_getch();
return 0;
}
the _getch(); will wait for a keypress to continue.
-
u must just be starting C++
I remember that program.
-
ya
ya i am, yall got any good suggestions of where i should start? I'm only 13 but i'm seriusoly into computers and stuff so i'm very determined....
-
i would suggest starting with tic tac toe
-
unregistered.. you problem is your DOS Settings not your hello world app.
do this
go to start/ click run / type in "COMMAND"/ go to the directory containing your hello world app and then run it.. you should be all good
-
ss3x... adding a getch() is more mobile and compatible.
restricting it to only work run from a dos window is pointless, when it only takes an extra line or 2 to make it mobile. ok?
-
Hello? conio is not standard so anything from it is not portable.
Do this:
Code:
#include <iostream>
using std::cout;
using std::cin;
int main()
{
cout << "Hello world\n";
cin.get(); // Pauses until enter is pressed
return 0;
}
-
biosx : i mean executable-wise it is portable.
what good is it if you have to spend 5 seconds getting to dos every time when you could spend 5 seconds once writing getch(); ??? plus if it was distribute, way more mobile
-
Just putting a getch() does not change anything. It is still a console application (notice I didn't say DOS application, b/c there is a difference between DOS programming and console programming).
however way you code it:
Code:
#include <iostream>
using std::cout;
using std::cin;
int main()
{
cout << "Hello world\n";
cin.get(); // Pauses until enter is pressed
return 0;
}
== and this ==
Code:
#include <iostream>
using std::cout;
#include <conio.h>
int main()
{
cout << "Hello world\n";
getch(); // Pauses until key is pressed
return 0;
}
... will still run in console windows without having to open up a cmd-term.
-
Oh jeez.... just use conio for now; it's easier. It really doesn't matter which way you use. Go buy a C++ book not published by sams and not a _____ for dummies book.