|
-
Oct 1st, 2000, 03:02 AM
#1
Ok, so I am just learning C++, don't get annoyed. I just want to know why this ends right away and doesn't stay in dos mode when I compile and run it in C++.
Code:
#include <iostream.h>
int main()
{
cout<<"Hello World!";
}
Ask a stupid question, get a stupid answer.
Thanks
-
Oct 1st, 2000, 04:11 AM
#2
Frenzied Member
The code outputs to a console window, which I thin kit slightly different to a DOS window. Anyway, that's just what happens when your code has finished executing. In the MSVC++6 IDE it waits for you to press a key when you've finished, but that's just for testing purposes.
Harry.
"From one thing, know ten thousand things."
-
Oct 1st, 2000, 04:30 AM
#3
Monday Morning Lunatic
Open up command.com and run it from the command line. Alternatively, #include <stdlib.h>, and put system("pause"); at the end of your program.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 1st, 2000, 04:35 AM
#4
Fanatic Member
Response
You have declared 'main' to return an int, which is good coding practice, but you don't return anything! Change your code to the following:
Code:
#include <iostream.h>
int main()
{
cout<<"Hello World!";
//Now we return 0!
return 0;
}
Also, when you compile, set the compile option to Win32 Release, as opossed to Win32 Debug. Hope this helps!
Bye
Digital-X-Treme
Contact me on MSN Messenger: [email protected]
[VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
/ (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]
-
Oct 1st, 2000, 09:02 AM
#5
Frenzied Member
Or...
You could put
#include <iostream.h>
void main()
{
cout << "Hello World!" << endl;
char a;
cout << "Press Any Key...";
cin >> a;
}
Which should work, basically it waits for u to press a key before quitting.
-
Oct 1st, 2000, 09:21 AM
#6
Fanatic Member
Or...
You could open a MS-DOS Prompt and run it by using
cd YourFolder
and then
YourApp.exe
That's what I did until I got bored of C++ since it seemed just like QBasic, but without the ease, so I moved on to Visual C++ which is more fun.
-
Oct 1st, 2000, 11:56 AM
#7
This should work.
Code:
#include <iostream.h>
void main()
{
int a;
cout << "Hello World!";
cin >> a;
}
-
Oct 1st, 2000, 01:46 PM
#8
Thanks everyone!
All your information has helped me much.
I think I am going to like C++ .
-
Oct 1st, 2000, 01:53 PM
#9
Monday Morning Lunatic
You will...it's a nice language. It's not perfect (some parts of C++ are a bit vile), but it's damn good for what it gives you.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 1st, 2000, 01:58 PM
#10
Re: Response
Originally posted by [Digital-X-Treme]
You have declared 'main' to return an int, which is good coding practice, but you don't return anything! Change your code to the following:
Code:
#include <iostream.h>
int main()
{
cout<<"Hello World!";
//Now we return 0!
return 0;
}
Also, when you compile, set the compile option to Win32 Release, as opossed to Win32 Debug. Hope this helps!
Bye
By the way, what does return 0; do?
-
Oct 1st, 2000, 02:01 PM
#11
Monday Morning Lunatic
Why post twice?
The return keyword returns the specified value, and exits the function. In C/C++, returning 0 from main indicates success.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 5th, 2000, 09:08 AM
#12
New Member
Originally posted by V(ery) Basic
That's what I did until I got bored of C++ since it seemed just like QBasic, but without the ease, so I moved on to Visual C++ which is more fun.
That is the SINGLE most IDIOTIC reason I have EVER heard for not learning 'standard' C++...And gee...I wonder why Qbasic is like it...
p.s. Visual C++ is gay. :)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|