Page 1 of 1
Piece of crap program...
Posted: Sat Dec 11, 2004 11:25 pm
by unasmer
Yea I got a book of c++ in 24 hours, and i installed the programs on the cd that came with it (DJGPP compiler, Dev-C++ IDE, and Cygnus Insight debugger). I tried running the simple "hello world" program just to check it out, and when i clicked compile and run, the "hello world" program would open but then close all within a split second. Any tips as to what I can do to keep this from happening?
Posted: Sun Dec 12, 2004 9:32 am
by Falco Girgis
Yeah, dude. Everybody has that exact same problem
.
Okay, I'm going to assume your sample program looked something like this:
Code: Select all
#include <iostream>
int main() {
cout >> "Hello World";
return 0;
}
Actually, the program did work. All that this says to do is say "Hello World" and exit. That flash is it saying your hello world. It is just really quick.
To stop it from dieing so fast like that, you would do something like this, and don't worry about what it means for now, your book will explain later.
Code: Select all
#include <iostream>
int main() {
int dumby_variable;
cout >> "Hello World";
cin << dumby_variable;
return 0;
}
Posted: Sun Dec 12, 2004 9:46 am
by Falco Girgis
He just told me on AIM that he was using C, not C++.
Also, the reason that it doesn't just close out on you at school is because Metroworks Codewarrior does this step for you and Dev-C++/VisualC++ doesn't.
Your code would look like this (doing this in typical Mrs. Rountree style because I think you have her):
Code: Select all
#include <stdio.h>
int main(void)
{
printf("Hello World");
return 0;
}
Now, we do the equivalent of what I did in C++ earlier. We are just getting user input before going to the next step (which is exitting the program in this case).
Basically, it won't exit until you push enter.
Code: Select all
#include <stdio.h>
int main(void)
{
int dumby_variable;
printf("Hello World");
scanf("%d", dumby_variable);
return 0;
}
Posted: Sun Dec 12, 2004 10:01 am
by unasmer
dude thanks falco