测试int [英] testing for int

查看:88
本文介绍了测试int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我是新手,这听起来很简单。我仍然需要

帮助,不知道在哪里找到它。


好​​的,这里是:


----

int vhold;


cin>> vhold;


// vhold在随后的循环中使用


----


如果输入是双倍的,则显示器会发生疯狂的事情。我如何测试

仅整数输入?


所有答案都将受到赞赏,最重要的是语法。 Thanx,


Andre

I know I am a newbie and this will sound very elementary. Still I need
help, and don''t know where to find it.

OK, here it is:

----

int vhold;

cin >> vhold;

// vhold used in a subsequent while loop

----

If input is double, crazy things happen to the display. How do I test for
only integer input?

All answers will be appreciated, exact syntax most of all. Thanx,

Andre

推荐答案

请你再详谈一下吗?
Can you please be a little bit more specific please?


我只是想知道如何确保我的progrram可以处理keybord

输入let''s say double或char,或string,if期望值为

int。


" Adam Cowherd" < 6 *********** @ gawab.com>在消息中写道

新闻:10 ************* @ corp.supernews.com ...
I just want to know how to make sure that my progrram can handle keybord
input of let''s say double or char, or string, if the expected value is an
int.

"Adam Cowherd" <vi***********@gawab.com> wrote in message
news:10*************@corp.supernews.com...
你能不能请一点点请更具体一点?
Can you please be a little bit more specific please?





" Andre" <有关********** @ hotmail.com>在消息中写道:

"Andre" <on**********@hotmail.com> wrote in message:
int vhold;
< snip> cin>> VHOLD;
< snip>如果输入是双倍的,那么显示器就会发生疯狂的事情。我如何
只测试整数输入?
int vhold; <snip> cin >> vhold; <snip> If input is double, crazy things happen to the display. How do I test for only integer input?




int n;

std :: cin>> n;

if(std :: cin.fail()){

//数据读取形式不正确。

}


Jonathan



int n;
std::cin >> n;
if (std::cin.fail()) {
// Data read was not in correct form.
}

Jonathan


这篇关于测试int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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