如何在C ++中捕获整数输入? [英] How do I trap integer inputs in C++?

查看:71
本文介绍了如何在C ++中捕获整数输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是我程序的一部分,我想使用while循环捕获整数输入。



This is just a portion of my program and I want to trap the integer inputs using while loop.

cout<<"\nEnter the name : ";
while(/*while input is integer or not in character*/)
{
   //Display invalid Input!
}
cin.ignore();
cin.getline(name, 100);

推荐答案

看起来你只需要允许字母输入。然后你需要进行验证的检查是 isalpha

http://www.cplusplus.com/reference/locale/isalpha [ ^ ]。



-SA
It looks like you need to allow only alphabet input. Then the check you need for validation would be isalpha:
http://www.cplusplus.com/reference/locale/isalpha[^].

—SA


这篇关于如何在C ++中捕获整数输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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