Having trouble running C++ compiler

  • C/++/#
  • Thread starter Benzoate
  • Start date
  • #1
420
0

Main Question or Discussion Point

The type of compiler I am using is Dev-C++. I have no problem compiling my code and my compiler has generated no errors. However , when I try to run my code, The command prompt for like a nano-second and disappears and I have no idea of how to retreive it .
 
Last edited:

Answers and Replies

  • #2
Hurkyl
Staff Emeritus
Science Advisor
Gold Member
14,916
17
The type of compiler I am using is Dev-C++. I have no problem compiling my code and my compiler has generated no errors. However , when I try to run my code, The command prompt for like a nano-second and disappears and I have no idea of how to retreive it .
The problem with computers is that they do exactly what you tell them to do. :smile: It sounds like you either need to run your program from a persistent command prompt, or change your program so that it doesn't finish immediately upon printing the output you want to see.
 
  • #3
264
70
It would help if you could post some code example which do not work for you, otherwise it is not very easy to help you.
 
  • #4
299
0
Check if there are any spaces in the names of any of the folders/subfolders/files that you are using for the compiler and name of your program file...

e.g. should be

C:\\MyDocuments\compiler\program.exe

NOT

C:\\My Documents\the compiler\test program.exe

(I also use Dev-C++, if I have any spaces in the names, it does exactly what you say yours does)
 
Last edited:
  • #5
246
6
With most newer IDE environments, when you execute a terminal program in windows, as soon as the program is terminated, the terminal window will close. There are ways to alter this behavior, but usually the best course of action is to open a persistent terminal window, and execute your program from there.

For example, go to "RUN" and type: cmd.

Then navigate to the directory where the program is compiled, for instance cd C:\users\administrator\documents\debug.

Then, you simply execute the program by invoking its name, for example, C:\helloworld.exe.

Your other option is to put some kind of pause statement at the end of your program, to allow you to view the output.

For instance:

int End1;
cin >> End1;
return 0;


Then, the program will wait for you to enter an integer, giving you time to view the programs output before the terminal window is closed.
 
  • #6
299
0
1.) Download and install Dev-C++. You can either use version 4.9.9.x or 5.0 (still beta). The setup should be just like any other windows program. However, you must install to a location that does not contain spaces. I don't know why this issue still exists but trust me on it. I chose to use C:\Dev-cpp\ for my location. (Download Dev-C++)

The Dev-C++ IDE
Pre-Installation Issues

We strongly recommend that Dev-C++ is installed and tested before installing any of the GTK+ or gtkmm libraries, as we will be installing all the libraries into the Dev-C++ directory. Ensure that you are able to successfully compile and run a simple C++ program from Dev-C++ before proceeding to the next step. For instance, try a simple Hello World program.

Note: Currently (as of v4.9.8.0) Dev-C++ does not like to be installed in directories with spaces in them. Installing Dev-C++ to the "Program Files" directory may cause problems at a later stage when it looks for the include and lib directories.
Select a folder where you would like to install DevC++. It's best if you don't use a folder that contains spaces, (such as "Documents and Settings"). As you can see here, I've created a folder named bin, where I install all of the programs that I use. Click Install once you've selected a folder:
I know it sounds weird, but it worked for me.
 

Related Threads for: Having trouble running C++ compiler

Replies
1
Views
2K
Replies
3
Views
592
  • Last Post
Replies
1
Views
1K
Replies
5
Views
6K
  • Last Post
Replies
0
Views
2K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
2
Views
2K
Replies
1
Views
3K
Top