C++ - 保持控制台窗口打开?

2022-01-11 00:00:00 windows console c++

我的问题非常简单,但我正在从 C# 过渡到 C++,我想知道在 C++ 中打开控制台窗口的命令是什么?

My question is super simple, but I'm transitioning from C# to C++, and I was wondering what command holds the console window open in C++?

我知道在C#中,最基本的方式是:

I know in C#, the most basic way is:

Console.ReadLine();

或者如果你想让用户按任意键,它:

Or if you want to let the user press any key, its:

Console.ReadKey(true);

你如何在 C++ 中做到这一点?我在这里问这个简单的问题的唯一原因是我无法在互联网上找到一个好的和明确的答案.

How do you do this in C++? The only reason I ask this simple of a question here, is that I haven't been able to find a good and clear answer out there on the internet.

推荐答案

std::cin.get(); 怎么样?

此外,如果您使用的是 Visual Studio,则无需调试即可运行(默认为 CTRL-F5),并且最终不会关闭控制台.如果你在调试的情况下运行它,你总是可以在 main() 的右大括号处放置一个断点.

Also, if you're using Visual Studio, you can run without debugging (CTRL-F5 by default) and it won't close the console at the end. If you run it with debugging, you could always put a breakpoint at the closing brace of main().

相关文章