gpt4 book ai didi

C++11 QtCreator : long integer not correctly read into variable

转载 作者:行者123 更新时间:2023-11-27 22:48:12 24 4
gpt4 key购买 nike

我有一个类型为 Node 的单向链表,定义如下:

struct Item {
long date;
bool isPaid;
};
struct Node{
Item item;
Node* next;
};

其中“日期”是一个将采用“ddmmaaaa”形式的字段(即,日期的前两位数字,月份的后两位数字,年份的最后四位数字)。但是,当我尝试添加几个节点时,我插入了一个不同的数字:

newItem=new Node;
newItem->item.date=01062016;
newItem->item.isPaid=true;
newItem->next=nullptr;
list=insertItem(list, newItem);

(insertItem 是我的函数,它接受一个指向列表头的指针和一个指向新节点的指针,并将该节点插入列表中)。

如果我尝试将 13042016 之类的内容分配给长字段,我会得到正确的数字:

this is right

但是,当我尝试分配 01062016 时,我得到的却是 287758:

this is wrong

我并没有尝试使用不同的方法(我知道日期很奇怪,我只是需要这种方式)。只是为了理解为什么我添加一个完全适合 long 变量的日期时会得到奇怪的数字。我正在使用基于 Qt 5.1.0 的 Qt Creator 2.7.2。

最佳答案

因为010620160开头而不是0x所以它是一个八进制数,它等价于287758十进制。

参见 Integral Literal :

octal-literal is the digit zero (0) followed by zero or more octal digits (0, 1, 2, 3, 4, 5, 6, 7)

关于C++11 QtCreator : long integer not correctly read into variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40819851/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com