Delimiter tens and units in c++ literals

半世苍凉 提交于 2019-12-02 11:37:22

问题


In Java I can do:

int i = 1_200_200;

How can I do something the same in c++? I mean what should I use instead of an underscore?


回答1:


Since C++14 you can use single quotes (') for integer literal to improve the readability, e.g.

int i = 1'200'200;

Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler.




回答2:


In C++ you can use the ordinary quote. For example

#include <iostream>

int main() 
{
    int x = 1'234'567;

    std::cout << "x = " << x << std::endl;

    return 0;
}

In C such a feature is absent.



来源:https://stackoverflow.com/questions/46254084/delimiter-tens-and-units-in-c-literals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!