C++ - 保持控制台窗口打开? [英] C++ - Hold the console window open?

查看:31
本文介绍了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().

这篇关于C++ - 保持控制台窗口打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆