八进制错误 [英] octal error

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

问题描述

我一直试图将0到9之间的数字用0领先。对于

示例00或07.我正在使用开关盒。

开关(int)

{

case 01:break;

case 02:break; .....

我的问题出现在08和09,因为它们不是八进制的。是否有任何方法将输入变量强制转换为十进制,尽管它有一个

前导零。

解决方案

notahipee写道:


我一直在试图从0到9中的一个数字,前导为0.对于

例如00或07.我使用的是开关盒。



您使用的是开关盒吗?


switch(int)



^^^^^^^^^^^

这是语法错误的陈述。


{

case 01:break;

case 02:break; .....

我的问题出现在08和09因为他们不是八进制。



会有什么问题?


有没有

任何方式将输入变量强制转换为十进制,尽管它具有

前导零。



这是你似乎遇到的一个实际问题的一线......但是

我没有看到所谓的行为以下程序。


#include< iostream>

#include< ostream>

int main()

{

int a = 666;

std :: cin> a;

std :: cout<< ; 你进入了 << a<< std :: endl;

}


如果我输入08,则打印''你输入8''。有什么问题?


V

-

请在回复时删除资金''A'电子邮件

我没有回复最热门的回复,请不要问


我想做的事情看起来像这个:

#include< iostream>

#include< ostream>

int main()

{

int a;


cout<< 输入一个数字 <<结束;

cin> a;

开关(a)

{

案例00:cout< <零;

案例01:cout<<零一个;



}

由于前导零将数字更改为八进制,因此它在08处崩溃并且

09.


notahipee写道:


我一直想尝试从0到9的数字前导为0.对于

示例00或07.我使用的是开关盒。

switch(int)

{

案例01:休息;

案例02:休息; .....

我的问题出现在08和09因为它们不是八进制。有没有

任何方法将输入变量强制转换为十进制,尽管它有一个

前导零。



请发布完整的,最少的代码来证明问题。


Brian


I have been trying to cin an number from 0 to 9 with a leading 0. For
example 00 or 07. I was using a switch case.
switch (int)
{
case 01: break;
case 02: break;.....
My problem arises at 08 and 09 because they are not octal. Is there
any way to coerce the input variable to decimal despite it having a
leading zero .

解决方案

notahipee wrote:

I have been trying to cin an number from 0 to 9 with a leading 0. For
example 00 or 07. I was using a switch case.

You were using a switch case for what?

switch (int)

^^^^^^^^^^^
That''s a syntactically incorrect statement.

{
case 01: break;
case 02: break;.....
My problem arises at 08 and 09 because they are not octal.

What problem would that be?

Is there
any way to coerce the input variable to decimal despite it having a
leading zero .

This is a glimmer of an actual problem you seem to be having... But
I am not seeing the alleged behaviour in the following program.

#include <iostream>
#include <ostream>
int main()
{
int a = 666;
std::cin >a;
std::cout << "you entered " << a << std::endl;
}

If I enter 08, it prints ''you entered 8''. What''s the problem?

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


What I was trying to do looks like this:
#include <iostream>
#include <ostream>
int main()
{
int a;

cout << "enter a number " << endl;
cin >a;
switch (a)
{
case 00: cout << zero;
case 01: cout << zero one;
etc.
}
Since a leading zero changes the number to octal it crashes at 08 and
09.


notahipee wrote:

I have been trying to cin an number from 0 to 9 with a leading 0. For
example 00 or 07. I was using a switch case.
switch (int)
{
case 01: break;
case 02: break;.....
My problem arises at 08 and 09 because they are not octal. Is there
any way to coerce the input variable to decimal despite it having a
leading zero .

Please post complete, minimal code that demonstrates the problem.


Brian


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

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