-1

I have this well known c++ program in my Visual Studio 2015 Prof:

#include <iostream>

int main(int argc, char* argv[]) {
    std::cout << "Hello World!" << std::endl;
    return 0;
}

As expected, it shows "Hello World!" if I hit Ctrl+F5. However, if I go to the directory within an cmd.exe and execute the HelloWorld.exe file, it doesn't show anything as output, but does quit (I can type in again).

According to a similar question I checked the settings of the project but I did not need to change anything, the Configuration Properties -> Linker -> System -> SubSystem already is at Console (/SUBSYSTEM:CONSOLE).

Flushing the std::cout also didn't help anything. It is reproducable on every freshly created project of VS2015 on my Win 7 64-bit machine and seems to be presistent after rebooting.

What is wrong with my IDE / settings?

  • `std::endl` does a flush (according to [this page](http://en.cppreference.com/w/cpp/io/manip/endl)) so adding a flush on top of that won't help (if that had been the problem). – Borgleader May 24 '17 at 12:08
  • This isn't the problem, but you're right that flushing the output stream doesn't affect this, and that's why you don't need `std::endl`; `'\n'` ends a line. – Pete Becker May 24 '17 at 12:09
  • Thanks for the fast reply. I don't know what the problem is, but the flushing (no matter if on top or below the std::cout) did not show anything either. – John.A.Myer May 24 '17 at 12:10
  • My VS2013 provides a start menu entry Tools/Developer Command Prompt. It probably opens the cmd.exe with necessary additions to paths. Did you try to run your application in this? – Scheff's Cat May 24 '17 at 12:19
  • Try this [StackOverflow answer](https://stackoverflow.com/a/2633814/8051589). – Andre Kampling May 24 '17 at 12:33
  • @Andre I think the OP did that already and documented it in the question. – πάντα ῥεῖ May 24 '17 at 12:35
  • Thanks for replies. I already did the setting (/SUBSYSTEM:CONSOLE), I can not do the AllocConsole part mentioned in the link from Andre Kampling, as this is in the header `windows.h`which I did not include (and think I should not?). I found a "Developer Prompt" in directory `... IDE\Microsoft Visual Studio 14.0\Common7\Tools` and checked if it really is working with `clrver`but it does not show any output either – John.A.Myer May 24 '17 at 12:48
  • @John.A.Myer I just tried to reproduce your problem in my VS2013. I created a new project, erased all this stdafx things and just typed your "Hello World" example. Ctrl+F5 fine (as in your case). Then I looked for the output directory (in the property dialog), opened cmd.exe and moved to this directory. Calling application from cmd.exe worked as well. So, bad news - cannot reproduce your problem. My guess was that the runtime library (which is linked in by VC) couldn't be found in your case. Therefore, I recommended to start the cmd.exe with extended environment for VS2013. – Scheff's Cat May 24 '17 at 13:06
  • @Scheff Thank you for your effort. I think this tells me, the problem is either on my combination of OS and IDE, or something in my system is messed up – John.A.Myer May 24 '17 at 13:10
  • ... If you installed VS as usual it should be provided as entry in the Windows Start menu. In my case it is Start/All Apps/Visual Studio 2013/Visual Studio-Tools which opens a folder where you find a link "Developer Command Prompt". Double clicking this I got a cmd (looking as usual) with probably extended environment. (I typed `echo %path% and saw a lot of VS related paths in it.) – Scheff's Cat May 24 '17 at 13:10
  • 1
    The question is whether your application does not find the necessary run-time and if - why. You could try to install the redistributables for this version of VS. In my case, I did this already in the past while trying our own software deploys. (This is valid for release version only.) You can try to find out about (missing) dependencies (to DLLs) using Dependency Walker. – Scheff's Cat May 24 '17 at 13:13

1 Answers1

0

After the hint of @Scheff I threw the exe file into "Dependency Walker". It gave me a missing UCRTBASED.DLL and lots of second and third level missing dlls (I think this is usually the case on every application?).

I somehow think my (recently installed) anti virus did interfere with that, because it shows some messages in the log regarding my HelloWorld.exe.

However, deinstalling anti virus and restarting machine did the trick. I can finally see Hello World! on cmd.exe.