Is there a way to catch the stderr and stdout in V

2019-02-11 20:05发布

Is there a way to catch the stdout and stderr in Visual Studio? For example, when I use

cout <<"Hello world!"<< endl;

A black window appears and disappears. It's so fast that I can't see it. There is a output section in the IDE but it only allow me to choose display output from build and something else but without the choice of stdout.

A cheating solution maybe calling

system("pause");

but it doesn't sound right. I searched in the option but I can't find an item.

Anyone has any idea? Thanks. I just start to use VS and I'm on Linux before.

3条回答
干净又极端
2楼-- · 2019-02-11 20:38

Go to Project Properties -> Linker -> System -> Change subsystem to Console.

查看更多
家丑人穷心不美
3楼-- · 2019-02-11 20:49

Without actually trying to redirect stdin/err streams, there are some alternatives you can try:

  • Open a command prompt window and cd to the directory your executable will be created in then run it from there.
  • Perhaps try using something like std::cin.get(); or std::cin.ignore(std::cin.rdbuf()->in_avail() + 1); instead of system("pause").
  • Display output in the visual studio debugger via OutputDebugString
查看更多
走好不送
4楼-- · 2019-02-11 20:53

Rather than using the "Start Debugging" command, if you want to check the output, use "Start Without Debugging". That's generally how I handle it. The command prompt window will remain up until you close it. If there's a crash or something, you can always reattach Visual Studio to the process, or just run it with "Start Debugging".

查看更多
登录 后发表回答