简体   繁体   中英

qDebug prints a wrong number

I'm just trying to print a number using qDebug as follows:

qDebug() << QString::number(03001);

But the result is:

"1537"

If I try to print without the first zero:

qDebug() << QString::number(3001);

The result is correct:

"3001"

Why does it happen?

I'm using Qt 5.3.

Leading zero will make the number to be interpreted as an octal literal .

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

So this is not by any means related to qDebug, but to the way C++ interprets integer constants .

03001是C ++中的八进制数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM