<i id='xUBVH'><tr id='xUBVH'><dt id='xUBVH'><q id='xUBVH'><span id='xUBVH'><b id='xUBVH'><form id='xUBVH'><ins id='xUBVH'></ins><ul id='xUBVH'></ul><sub id='xUBVH'></sub></form><legend id='xUBVH'></legend><bdo id='xUBVH'><pre id='xUBVH'><center id='xUBVH'></center></pre></bdo></b><th id='xUBVH'></th></span></q></dt></tr></i><div id='xUBVH'><tfoot id='xUBVH'></tfoot><dl id='xUBVH'><fieldset id='xUBVH'></fieldset></dl></div>

      <bdo id='xUBVH'></bdo><ul id='xUBVH'></ul>

    1. <tfoot id='xUBVH'></tfoot>
    2. <legend id='xUBVH'><style id='xUBVH'><dir id='xUBVH'><q id='xUBVH'></q></dir></style></legend>

      <small id='xUBVH'></small><noframes id='xUBVH'>

    3. 前面为 0 的 C++ int 更改整个值

      时间:2023-05-24
      <i id='oKWi7'><tr id='oKWi7'><dt id='oKWi7'><q id='oKWi7'><span id='oKWi7'><b id='oKWi7'><form id='oKWi7'><ins id='oKWi7'></ins><ul id='oKWi7'></ul><sub id='oKWi7'></sub></form><legend id='oKWi7'></legend><bdo id='oKWi7'><pre id='oKWi7'><center id='oKWi7'></center></pre></bdo></b><th id='oKWi7'></th></span></q></dt></tr></i><div id='oKWi7'><tfoot id='oKWi7'></tfoot><dl id='oKWi7'><fieldset id='oKWi7'></fieldset></dl></div>
        • <bdo id='oKWi7'></bdo><ul id='oKWi7'></ul>

            <tfoot id='oKWi7'></tfoot>
                <tbody id='oKWi7'></tbody>

              • <small id='oKWi7'></small><noframes id='oKWi7'>

                <legend id='oKWi7'><style id='oKWi7'><dir id='oKWi7'><q id='oKWi7'></q></dir></style></legend>
                本文介绍了前面为 0 的 C++ int 更改整个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有一个非常奇怪的问题,如果我像这样声明一个 int

                I have this very strange problem where if I declare an int like so

                int time = 0110;
                

                然后显示到控制台返回的值为72.但是,当我删除前面的 0 以便 int time = 110; 控制台然后像预期的那样显示 110 .

                and then display it to the console the value returned is 72. However when I remove the 0 at the front so that int time = 110; the console then displays 110 like expected.

                我想知道两件事,首先为什么它在 int 的开头使用前面的 0 来执行此操作,并且有没有办法阻止它,以便 0110 至少等于110?
                其次,有没有什么办法可以让0110返回0110?
                如果您对变量名称进行猜测,我会尝试在 24 小时内进行操作,但此时 1000 之前的任何时间都会因此导致问题.

                Two things I'd like to know, first of all why it does this with a preceding 0 at the start of the int and is there a way to stop it so that 0110 at least equals 110?
                Secondly is there any way to keep it so that 0110 returns 0110?
                If you take a crack guess at the variable name I'm trying to do operations with 24hr time, but at this point any time before 1000 is causing problems because of this.

                提前致谢!

                推荐答案

                从 0 开始的整数字面量定义了八进制整数字面量.现在在 C++ 中有四类整数文字

                An integer literal that starts from 0 defines an octal integer literal. Now in C++ there are four categories of integer literals

                integer-literal:
                    decimal-literal integer-suffixopt
                    octal-literal integer-suffixopt
                    hexadecimal-literal integer-suffixopt
                    binary-literal integer-suffixopt
                

                八进制整数字面量定义如下

                And octal-integer literal is defined the following way

                octal-literal:
                    0 octal-literal
                    opt octal-digit
                

                就是从0开始.

                因此这个八进制整数文字

                Thus this octal integer literal

                0110
                

                对应下面的十进制数

                8^2 + 8^1 
                

                即等于 72.

                您可以通过运行以下简单程序来确定八进制表示中的 72 等于 110

                You can be sure that 72 in octal representation is equivalent to 110 by running the following simple program

                #include <iostream>
                #include <iomanip>
                
                int main() 
                {
                    std::cout << std::oct << 72 << std::endl;
                
                    return 0;
                }
                

                输出是

                110
                

                这篇关于前面为 0 的 C++ int 更改整个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:我在哪里可以找到 size_t 的定义? 下一篇:将变量名转换为 C++ 中的字符串

                相关文章

                最新文章

              • <small id='0743j'></small><noframes id='0743j'>

                <tfoot id='0743j'></tfoot>
                <legend id='0743j'><style id='0743j'><dir id='0743j'><q id='0743j'></q></dir></style></legend>

              • <i id='0743j'><tr id='0743j'><dt id='0743j'><q id='0743j'><span id='0743j'><b id='0743j'><form id='0743j'><ins id='0743j'></ins><ul id='0743j'></ul><sub id='0743j'></sub></form><legend id='0743j'></legend><bdo id='0743j'><pre id='0743j'><center id='0743j'></center></pre></bdo></b><th id='0743j'></th></span></q></dt></tr></i><div id='0743j'><tfoot id='0743j'></tfoot><dl id='0743j'><fieldset id='0743j'></fieldset></dl></div>

                    • <bdo id='0743j'></bdo><ul id='0743j'></ul>