| | |
dev-c++ Premature Closing
![]() |
•
•
Join Date: Dec 2004
Posts: 10
Reputation:
Solved Threads: 0
Hey all, I posted a question earlier this week regarding dev-c++ and my inability to keep the output window (#include <iostream>) open long enough to see my program running!
I have already tried the following things and would be grateful for any other suggestions!
1:
(Without typing using namespace std
\\At the top
std::cout << "Press enter to exit";
std::cin.ignore(std::cin.rdbuf()->in_avail + 1);
return 0;
2:
(Typing using namespace std
\\At the top
cout << "Press enter to exit";
cin.ignore(cin.rdbuf()->in_avail + 1)
return 0;
3:
#include <cstdio> \\At the top
cout << "Press enter to exit";
getchar();
return 0;
Someone please help! I seem to have tried everything! If anyone knows dev-c++, could you give me a sure fire way of keeping the output window open! Thank you!
(And thanks to the guys or gals who have already suggest ways to help!)
I have already tried the following things and would be grateful for any other suggestions!
1:
(Without typing using namespace std
\\At the topstd::cout << "Press enter to exit";
std::cin.ignore(std::cin.rdbuf()->in_avail + 1);
return 0;
2:
(Typing using namespace std
\\At the topcout << "Press enter to exit";
cin.ignore(cin.rdbuf()->in_avail + 1)
return 0;
3:
#include <cstdio> \\At the top
cout << "Press enter to exit";
getchar();
return 0;
Someone please help! I seem to have tried everything! If anyone knows dev-c++, could you give me a sure fire way of keeping the output window open! Thank you!
(And thanks to the guys or gals who have already suggest ways to help!)
C++ Syntax (Toggle Plain Text)
#include <cstdio> \\At the top cout << "Press enter to exit"; getchar(); return 0;
This sounds like a common error to me. In DevC++ MAKE SURE that if you are using console output (cout) or generally not using a window for display then make sure in "Project Options" (right click project in class browser pane) you have "Win32 Console" selected. If you have "Win32 GUI" selected the program compiles as a windows app and will terminate at the end, ignoring console commands such as cin!
http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
try this
This code creates a program that displays hello and quits when you press enter...
C++ Syntax (Toggle Plain Text)
#include <cstdio> #include <iostream> using namespace std; int main(void) { cout << "Hello! Press enter to quit\n"; getchar(); return 0; }
http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
In Dev-C++ go File > New > Project > Console Application > give the project a name > OK > create a directory, open it and save the .dev file there. A skeleton file comes up, flesh this one out with your code. The skeleton file has system("PAUSE") and the required #include <cstdlib> already there for your program to wait appropriately. What more do you want?
[php]// the Dev C++ skeleton file for Console Apps
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
// ... your code and more ...
system("PAUSE");
return EXIT_SUCCESS;
}
[/php]
system("PAUSE") should be replaced with cin.get() for better portability!!!!
[php]// the Dev C++ skeleton file for Console Apps
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
// ... your code and more ...
system("PAUSE");
return EXIT_SUCCESS;
}
[/php]
system("PAUSE") should be replaced with cin.get() for better portability!!!!
May 'the Google' be with you!
•
•
Join Date: Jan 2005
Posts: 2
Reputation:
Solved Threads: 0
I am having the same problem.
It seems that certain function calls cause the window to close. For example, when this function is called, the output window closes immediately and I have no idea why. All function calls before and after(when the following is commented out) work fine. Any ideas?
/* A recursive definition with cache. */
int calcFast(int n){
start = clock();
int cache[n + 1];
for(int i = 0; i <= n; i++){
cache[i] = -1;
}
cache[0] = 0;
cache[1] = 1;
return calcFastHelper(n, cache);
}
/* Helper method. Only called by calcFast() */
int calcFastHelper(int n,int cache[]){
if (cache[n] >= 0)
return cache[n];
else{
cache[n] = calcFastHelper(n-1, cache) + calcFastHelper(n-2, cache);
return cache[n];
}
}
Edit: I wanted to add that I am using the version 5.0 beta for Windows XP in case that makes a difference from the v4.0.
Edit 2: Having downloaded and tried it in the old v4.0, here are a few things found.
The program now works but REQUIRES that system("PAUSE") and cstdlib header be included to work without prematurely closing.
If someone knows a way around this with v5.0 beta, that would be great. It's a bit irritating having to do "work arounds" when the code is required to be written a particular way for a class. Thanks.
It seems that certain function calls cause the window to close. For example, when this function is called, the output window closes immediately and I have no idea why. All function calls before and after(when the following is commented out) work fine. Any ideas?
/* A recursive definition with cache. */
int calcFast(int n){
start = clock();
int cache[n + 1];
for(int i = 0; i <= n; i++){
cache[i] = -1;
}
cache[0] = 0;
cache[1] = 1;
return calcFastHelper(n, cache);
}
/* Helper method. Only called by calcFast() */
int calcFastHelper(int n,int cache[]){
if (cache[n] >= 0)
return cache[n];
else{
cache[n] = calcFastHelper(n-1, cache) + calcFastHelper(n-2, cache);
return cache[n];
}
}
Edit: I wanted to add that I am using the version 5.0 beta for Windows XP in case that makes a difference from the v4.0.
Edit 2: Having downloaded and tried it in the old v4.0, here are a few things found.
The program now works but REQUIRES that system("PAUSE") and cstdlib header be included to work without prematurely closing.
If someone knows a way around this with v5.0 beta, that would be great. It's a bit irritating having to do "work arounds" when the code is required to be written a particular way for a class. Thanks.
There will almost certainly be an error in the function which causes the closing. From experience DevC++ loves doing this if you give a variable an invalid value....
As for closing it is fairly easy to stop the program close at the end. When it hits "return 0;" its all over, YOU need to stop it from closing (a common mistake). cin.get;, getchar(); (include stdlib) and system("PAUSE"); (include stdlib) work fine
As for closing it is fairly easy to stop the program close at the end. When it hits "return 0;" its all over, YOU need to stop it from closing (a common mistake). cin.get;, getchar(); (include stdlib) and system("PAUSE"); (include stdlib) work fine
http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
•
•
Join Date: Jan 2005
Posts: 2
Reputation:
Solved Threads: 0
My point is, when I omit the one line of code that calls the above mentioned function, it works fine, and the output window does not close. However, as soon as I include the above mentioned function it immediately closes, even with system("PAUSE") or getchar(). Again, that is with v5.0, with v4.0 it works fine.
again: it is the function causing the error. invalid values are the MOST common cause for it to QUIT WITHOUT making a MS Windows error box. New versions have probably disguised the error and made the closing the only visible clue, that is where the error is though
http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
•
•
•
•
Originally Posted by ap487
I am having the same problem.
It seems that certain function calls cause the window to close. For example, when this function is called, the output window closes immediately and I have no idea why. All function calls before and after(when the following is commented out) work fine. Any ideas?
/* A recursive definition with cache. */
int calcFast(int n){
start = clock();
int cache[n + 1];
for(int i = 0; i <= n; i++){
cache[i] = -1;
}
cache[0] = 0;
cache[1] = 1;
return calcFastHelper(n, cache);
}
/* Helper method. Only called by calcFast() */
int calcFastHelper(int n,int cache[]){
if (cache[n] >= 0)
return cache[n];
else{
cache[n] = calcFastHelper(n-1, cache) + calcFastHelper(n-2, cache);
return cache[n];
}
}
Edit: I wanted to add that I am using the version 5.0 beta for Windows XP in case that makes a difference from the v4.0.
Edit 2: Having downloaded and tried it in the old v4.0, here are a few things found.
The program now works but REQUIRES that system("PAUSE") and cstdlib header be included to work without prematurely closing.
If someone knows a way around this with v5.0 beta, that would be great. It's a bit irritating having to do "work arounds" when the code is required to be written a particular way for a class. Thanks.
May 'the Google' be with you!
![]() |
Other Threads in the C++ Forum
- Previous Thread: Sizeof operator help
- Next Thread: need help with group compiling c/c++ programs
| Thread Tools | Search this Thread |
api array auto based binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count delay-loading delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






