使用getch()来保持命令提示符打开Visual C ++ 2010 [英] using getch() to hold command prompt open Visual C++ 2010

查看:223
本文介绍了使用getch()来保持命令提示符打开Visual C ++ 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习c ++从一本名为Ivor Hortons开始Visual c + + 2010。

Im currently learning c++ from a book called 'Ivor Hortons Beginning Visual c++ 2010'.

在我到目前为止所有的例子,使用getch()保持打开命令提示符,有时从main方法结束时删除return 0语句。

In all the examples i've attempted so far I've had to use getch() to hold open the command prompt, and sometimes remove the return 0 statement from the end of the main method.

这是一个变化的windows 7它会进一步下线吗?这是没有问题,这一刻,但因为这不包括在书中,我想知道是否可能是我设置了错误。

Is this a vagary of windows 7 and will it cause problems further down the line? It's no problem doing this at the moment but since this is not included in the book I was wondering if it might be something I've set up wrong.

非常感谢: )

推荐答案

getch()不是操作系统特定的,不是直接便携。在 C ++ 中执行此操作的首选方法是使用 std :: cin.get();

getch() is not operating system specific, but it is not directly portable. The preferred method for doing this in C++ is to use std::cin.get();.

main 函数可以返回0 需要实际具有该代码,见下文)。

The main function can return 0 implicitly (you don't need to actually have that code, see below).

int main()
{
   // valid, return 0 implied.
}

查看返回0 从的更多细节, >。

See this question for more details about the implicit return 0 from main.

这篇关于使用getch()来保持命令提示符打开Visual C ++ 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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