有没有一种方法可以在C ++源代码中编写大量带有空格的内容,以使其更具可读性? [英] Is there a way to write a large number in C++ source code with spaces to make it more readable?

查看:25
本文介绍了有没有一种方法可以在C ++源代码中编写大量带有空格的内容,以使其更具可读性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下我的代码:

vector<int> temp = vector<int>(1 000 000 000);

以上内容将不会编译,因为编译器将抱怨空格.是否有可能在编译时指示C ++忽略那些空格,或者使数字更易于阅读?

The above will not compile as the compiler will complain about the spaces. Is it possible to indicate to C++ to ommit those spaces when compiling, or otherwise make the number easier to read?

推荐答案

尝试数字分隔符:

int i = 1'000'000'000;

C ++ 14起引入了此功能.它使用单引号(')作为数字分隔符.

This feature is introduced since C++14. It uses single quote (') as digit separator.

另请参阅:

  • Why was the space character not chosen for C++14 digit separators?
  • Generalizing Overloading for C++2000 (April's joke by the father of C++ himself)

这篇关于有没有一种方法可以在C ++源代码中编写大量带有空格的内容,以使其更具可读性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆