# Help with Dev-C++



## Spatcher (Apr 28, 2005)

i have dev-c++, and i just downloaded it. but when i creates the hello world program, the output just flashes on the screen so i can't read it. it loads, but just as soon as its done loading it exits. i was wondering if this is normal? or i dunno...


----------



## johnwill (Sep 26, 2002)

It sounds like you're creating a console application, but that's just a guess. Since I have no experience with that C++ compiler, and you didn't show us any code, it's hard to guess what you're seeing...


----------



## Spatcher (Apr 28, 2005)

yes it is a console application, but what code, is this it?

#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}


----------



## 2d3x (Apr 29, 2005)

Console applications will close automatically, so you need to add code that will wait for some type of response. I suggest you add 

system("PAUSE");

at the end of your code, or before return 0; if you have that in there. For example:

#include <iostream>

using namespace std;

int main()
{
cout<<"Hello World!\n";
 system("PAUSE");
}

That should be a good starting point, but you should play around with other ways to wait for input such as cin.get();


----------



## 2d3x (Apr 29, 2005)

HenryVI said:


> yes it is a console application, but what code, is this it?
> 
> #include <stdio.h>
> int main()
> ...


You could change this code in the following way:

#include <stdio.h>
int main()
{
printf("Hello World\n");
 system("PAUSE"); 
return 0;
}

That should make it say: "Press any key to continue..." and then wait for input.


----------



## elf (Jul 19, 2002)

2d3x said:


> You could change this code in the following way:
> 
> #include <stdio.h>
> int main()
> ...


but if the code is c++ this would not work...seeing as how this is c :4-dontkno


----------



## LoneWolf071 (Nov 10, 2004)

in order to use the system command, you must include the stdlib.h because that is what is needed... the system command acts like a one-line command interface, so you sould do like system("ls-l") to get it to list the dir or stuff like that... but in order to use it, you must declare the stdlib.h in the beginning.


----------



## Spatcher (Apr 28, 2005)

i added in the system("PAUSE"); and it still did the same thing, flash on the screen. maybe i should uninstall dev-c++ and go out and buy a tutorial book that includes a c++ cd?


----------



## johnwill (Sep 26, 2002)

Have you executed the compiled application in a command prompt? I sounds like this compiler isn't really generating a Windows application in the sense that it handles the screen that well. As I mentioned, I know nothing about the compiler or it's capabilities. From looking on the download site, it sure seems that it should be able to generate a Windows compatible application. Did you do some looking through the debug and run options for options to keep the window open?

Update, did you look at the FAQ?

*1. When I compile my dos program and execute it, Dev-C++ minimizes and then restore in a second but nothing appears ?

When creating a console application, be sure to uncheck “Do not create a console” in Project Options (when working with source files only uncheck “Create for win32” in Compiler Options).


2. When executing my dos program, it closes automatically. How I can change this ?

You can use an input function at the end of you source, like the following example :

#include <stdlib.h>
int main()
{
system(“PAUSE”);
return 0;
}*


----------



## Spatcher (Apr 28, 2005)

ok this is my code
#include <stdlib.h>
int main()
{
system("PAUSE");
return 0;
}
but i cant add in printf("Hello World\n"); i get an error. when i run the above source code the result is a box that says "Press any key to continue..."
to johnwill- doy! why didn't i do that in the first place? that would have saved a few posts lol! but it did help, thanks


----------



## LoneWolf071 (Nov 10, 2004)

```
#include <stdio.h>
#include <stdlib.h>

int main()
{
printf("Hello World\n");
system("pause");
return 0;
}
```
this works, but only on windows... not sure the linux command...


----------



## love_bytes2 (Apr 15, 2005)

HenryVI said:


> i have dev-c++, and i just downloaded it. but when i creates the hello world program, the output just flashes on the screen so i can't read it. it loads, but just as soon as its done loading it exits. i was wondering if this is normal? or i dunno...


Hello buddy!
u simply include i.e. #include<stdio.h> and at the end of the programme before closing the main body bracket type getch(); and u got what u want...


----------



## fang125 (Nov 24, 2005)

I know exactly how to do what you are talking about....
Here is a string that will work for you:

#include <iostream>
#include <stdlib.h>
using namespace std;

int main ()

{
cout << "Hello World...";
system("PAUSE");
return 0;
}


This string is a basic one that works... I tried it on my Dev C++ compiler... Hope this helped


----------



## fang125 (Nov 24, 2005)

When you figure that one out, try this...It was my second program...I made it in school because I was bored, but I do have a life... It was either I did that or I did that or slept, and I have insomnia so that idea is gone...Anywayz...Heres a simple program, matrix.cpp..I though it wa pretty cool and so did my class:


//This program is similar to the computers in the Matrix...
#include <iostream>
#include <stdlib.h>
using namespace std;

int main ()

{
int n;
cout << "Press 98765 and then enter to enter the matrix > ";
cin >> n;

while (n>0) {
cout << n << ", ";
--n;
}
cout << "Matrix terminated...";
system("PAUSE");
return 0;
}


----------



## DumberDrummer (Oct 27, 2003)

What I did when I was learning the basics was to just have a "Press Key to continue command that returned nothing. 

So I think something like this: (Been Awhile, so bear with me.)


```
int x;
cout << "Press Any key to end program";
cin >> x;

return 0;
```
This simply makes it wait for a keypress so you can examine the output. 

Of course, any of the things suggested below would work, this is just my preferred method.


----------



## tgo (Jul 5, 2005)

Why cant you just run your app from cmd prompt? (start - run - cmd)

then you wont have to worry about any of this thread. Also if your coding in ssh it will do this for you since terminal will act the same way as the cmd prompt.


----------

