输入包含前导零 [英] input containing leading zeroes

查看:211
本文介绍了输入包含前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在c ++中,如果我们输入一个包含前导zereos的整数,它们将是任何错误。

In c++ will their be any error if we input an integer containing leading zereos.

例如:

 int a;
 cin>>a;

我们输入00或01.

we give an input 00 or 01.

推荐答案

这是一个更好的主意。没有前导零。如果你想保持前导零,那么你必须读取输入的字符串,而不是,需要时将其转换为数字。或者,您可以使用格式在打印结果时添加前导零。

Integers (or floats for that matter) do not have leading zeroes. If you want to keep the leading zeroes then you have to read the input as a string instead, and convert it to number when needed. Or you can use formatting to add leading zeroes when printing results.

这篇关于输入包含前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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