Hello.cpp
Hello folk! I''m haven alittle bit of trouble with my first programm. I just downloaded a compiller and tried to write a hello world program. The program run for about a second to show hello but then goes away. can some one tell me home to get this to not happen. My code is as follows...
#include
int main()
{
cout<<"hello world!";
return 0;
}
is it my code? i appreciate you time in reading this and helping me.
Thank you.
October 02, 2000 09:11 PM
I am of no help.
I also wrote one these programs and could find no way of pausing the program.
I know the keyword is: PAUSE in BASIC but i have no idea what it is in C++.
You may try a loop that runs until it detects a key stroke.
I also wrote one these programs and could find no way of pausing the program.
I know the keyword is: PAUSE in BASIC but i have no idea what it is in C++.
You may try a loop that runs until it detects a key stroke.
Basically the compiler is running the program and then closing the window so fast that you can''t see what i happening. try running it from dos. that should work just fine.
Hope I helped,
Rob
Hope I helped,
Rob
Okay, I think your problem is that it is running in a DOS Console...you're running a Windows machine, right?
Anyhow, I've run into this same problem using Borland Builder 4 at school. What you need to do is include conio.h. Before your return 0; statement, use getch(); Like this:
Try that...it should work.
Oh, BTW, Borland Builder 4 is pure evil. It's almost Visual Basic for C/C++!
P h a n t a s m -- "Through dreams I influence mankind."
Edited by - Phantasm on October 2, 2000 10:18:46 PM
Anyhow, I've run into this same problem using Borland Builder 4 at school. What you need to do is include conio.h. Before your return 0; statement, use getch(); Like this:
#include #include int main() { cout << "hello world"; // getch() makes the program wait for the user to hit // a key. It's use is more powerful than that, but for // C++ programs, this is all you need to know for now. getch(); return 0;} // end main()
Try that...it should work.
Oh, BTW, Borland Builder 4 is pure evil. It's almost Visual Basic for C/C++!
P h a n t a s m -- "Through dreams I influence mankind."
Edited by - Phantasm on October 2, 2000 10:18:46 PM
Phantasm
The html in this forum strips the angle brackets from messages,
the include libraries are
#include iostream.h
#include conio.h
just put em in angle brackets and you should be right
Cel
the include libraries are
#include iostream.h
#include conio.h
just put em in angle brackets and you should be right
Cel
Cel aka Razehttp://chopper2k.qgl.org
When I made this program, I made a new c++ source file, wrote code, and compiled. The following worked fine:
#include
void main()
{
cout<<"Hello World"<}
I dunno why it won''t work above.
#include
void main()
{
cout<<"Hello World"<}
I dunno why it won''t work above.
Peon
i think it depends on the compiler you use, VC++ 6 will pause but e.g. Dev-C++ won''t
you can include cstdlib and call system("PAUSE"); before you return from main()
you can include cstdlib and call system("PAUSE"); before you return from main()
The reason the above one wouldn't work, is because you used int as the return type, then instructed main to return(0); This says that the program is over and done with, and closes the window out. The new program you wrote specifies that main's return type is void, and you don't return anything so the window stays open. The code is:
#include iostream.h //remember to include angle brackets!
void main(void)
{
cout << "Hello World";
}
This program ends, and doesn't do anything else, but it doesn't close the window (I'm pretty sure). The use of the getch() function waits for a keypress to end the program, then you have to close the window manually. But returning zero closes it out automatically. I don't think it has anything to do with which compiler you use.
Edited by - Opticon on October 3, 2000 12:47:27 PM
#include iostream.h //remember to include angle brackets!
void main(void)
{
cout << "Hello World";
}
This program ends, and doesn't do anything else, but it doesn't close the window (I'm pretty sure). The use of the getch() function waits for a keypress to end the program, then you have to close the window manually. But returning zero closes it out automatically. I don't think it has anything to do with which compiler you use.
Edited by - Opticon on October 3, 2000 12:47:27 PM
Well you could use a basic system function I dunno if it works with your compiler it should! (I''m using Dev C++ 4.0)
Matthew Fitzgerald (Maketty),
Knightvision Games
#include int main() { cout << "Text goes here"; return 0; // Right here is the system function system ("pause") } // I hope that works I''m sorry for any errors I may have missed // but you get the idea right? = ) // Goodluck
Matthew Fitzgerald (Maketty),
Knightvision Games
Maketty (Matthew FitzGerald) The meaning of Life part 5:Live organ transplants...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement