My C++ code is not running the way it shouldbrowsing

I am using Notepad++ with C++ and I have a short program that prompts the user to enter an integer. After he enters his number, the program should output the number that he just entered. But for whatever reason, after I enter my number into the program and hit Enter, the program just vanishes. It doesn’t echo the number that I just entered. I’m using MinGW.

The “NPP_RUN” is executing it in a separate process; as soon as that process is done, the window goes away; so if you want to keep the NPP_RUN to keep it in a separate window, then you need to have a system(“pause”) or similar at the end of your C++ program.

Alternatively, if you want the program to just dump its output in the NppExec console, just like the output of g++, you could use either of:

(If you use one of these, you have to be more careful with flusing STDOUT, if you want to see any prompts before the requested user input)

I tested with this self-contained example (using gcc as my compiler, rather than g++)

#include <stdio.h>
main() {
int d;
printf("hello, world\n");
fflush(stdout);
fscanf(stdin, "%d", &d);
printf("goodbye(%d)\n", d);
fflush(stdout);
//system("pause"); // use this line if you want to keep the npp_run to run in a separate window
}

Also, put "$(NAME_PART)" in the quotes, just like you put "$(FILE_NAME)" in quotes: if $(FILE_NAME) has a space that you need to protect against, so will $(NAME_PART) (except in the very rare occasion when your file extension has a space… but that probably won’t happen with a .c or .cpp file).

Some of the output letters are being cut off. Also the system pause thing makes no difference. I would like to view the output from all my programs in the external black DOS window if possible. I know Notepad++ can be set up to view your program in the internal output window, but I would also like to know how to set it up so I can view both kinds of programs in an external window. What I mean by both kinds of programs is programs that simply output something to the screen, and programs that ask for user input.

The lack of the waiting is not the fault of NPP nor NppExec: it’s the way the cmd.exe works. If you were to compile your same program (whether or not thru the NppExec interface) then use Windows Start Menu > Run > "G:\C++ Projects\GettingInput.exe" or …Run > cmd.exe /C "G:\C++ Projects\GettingInput.exe", the cmd.exe window would disappear just after, unless you have something (either a second c fscanf or c++ cin or whatever they call that input stream – sorry, I’m not a c++ expert – or a system("pause") requesting the user HIT ENTER before terminating the GettingInput.exe) – unless you have that pause, the cmd.exe window will disappear.

In case you don’t know, there’s a cmd /K option that runs any arguments passed to it in a separate cmd.exe processes, and then stays at that cmd.exe's prompt rather than exiting, which is probably what you want. (See below.)

Further debugging for you: Looking at your output, the source didn’t compile, hence the g++ fatal error. (Presumably, after the fatal error, it was running a previously-compiled version of your executable, rather than the most recent update.) Based on the error message, my guess is that it’s the smart quotes shown in your output for “GettingInput.cpp” instead of standard quotes in "GettingInput.cpp"; with proper quotes, and my source code, it works for me (see below).

For the c example I gave, to use system("pause") you also need to include stdlib.h (sorry, I hadn’t tested the system("pause")). But once I have that, it works for me as I’ve described.

Note that I flush stdout, like I mentioned yesterday, to make sure that “some of the output letters” don’t get “cut off”. When I don’t flush, some of the letters do get cut off. (That’s a “feature” of the gnu compiler; it changes auto-flush behavior when it’s going to a terminal/console vs output being piped (and it considers the NppExec framework to be a pipe).)

I used this exact NppExec script (copy/pasted from my NppExec “Execute…” dialog):