C ++文字中的分隔符十和单位
Delimiter tens and units in c++ literals
在Java我能做到:
int i = 1_200_200;
如何在 C++ 中做同样的事情?我的意思是我应该用什么来代替下划线?
从 C++14 开始,您可以对 integer literal 使用单引号 (') 以提高可读性,例如
int i = 1'200'200;
Optional single quotes(') may be inserted between the digits as a
separator. They are ignored by the compiler.
在C++中你可以使用普通引号。例如
#include <iostream>
int main()
{
int x = 1'234'567;
std::cout << "x = " << x << std::endl;
return 0;
}
在 C 中没有这样的功能。
在Java我能做到:
int i = 1_200_200;
如何在 C++ 中做同样的事情?我的意思是我应该用什么来代替下划线?
从 C++14 开始,您可以对 integer literal 使用单引号 (') 以提高可读性,例如
int i = 1'200'200;
Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler.
在C++中你可以使用普通引号。例如
#include <iostream>
int main()
{
int x = 1'234'567;
std::cout << "x = " << x << std::endl;
return 0;
}
在 C 中没有这样的功能。