C/C++ Having trouble running C++ compiler

Click For Summary
The discussion focuses on issues encountered when running code in Dev-C++, specifically the command prompt window closing immediately after execution. Users suggest running the program from a persistent command prompt to prevent the window from disappearing. This can be done by navigating to the program's directory using the command line and executing the program directly. Another solution is to add a pause at the end of the code, such as using a cin statement, to allow time to view the output before the program terminates. Additionally, it's emphasized that Dev-C++ should be installed in directories without spaces to avoid compilation issues, as spaces in folder names can lead to problems with execution. Users are encouraged to test simple programs first to ensure the setup is correct before proceeding with more complex coding tasks.
Benzoate
Messages
418
Reaction score
0
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:
Technology news on Phys.org
Benzoate said:
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.
 
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.
 
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:
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.
 
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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 29 ·
Replies
29
Views
3K
Replies
6
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
Replies
14
Views
3K
  • · Replies 0 ·
Replies
0
Views
2K
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K