Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只是想使用qDebug如下方式打印一个数字:
qDebug
qDebug() << QString::number(03001);
但结果是:
"1537"
如果我尝试在没有第一个零的情况下打印:
qDebug() << QString::number(3001);
结果是正确的:
"3001"
为什么会这样?
我正在使用 Qt 5.3。
前导零将使数字被解释为八进制文字。
八进制文字是数字零 (0) 后跟零个或多个八进制数字 (0, 1, 2, 3, 4, 5, 6, 7)
因此,这与 qDebug 无关,而是与 C++ 解释整数常量的方式有关。
03001 是 C++ 中的八进制数。