带单引号的整数文字?
Integer literal with single quotes?
赋值的究竟是什么?我很惊讶这已经编译好了。
//g++ 7.4.0
#include <iostream>
int main()
{
auto value = 123'456'7;
std::cout << value << std::endl;
value += 1;
std::cout << value << std::endl;
}
输出:
1234567
1234568
C++ 允许单引号分隔数字以便于阅读:
https://en.cppreference.com/w/cpp/language/integer_literal
Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler.
自 C++14 起,
来自 https://en.cppreference.com/w/cpp/language/integer_literal
Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler.
赋值的究竟是什么?我很惊讶这已经编译好了。
//g++ 7.4.0
#include <iostream>
int main()
{
auto value = 123'456'7;
std::cout << value << std::endl;
value += 1;
std::cout << value << std::endl;
}
输出:
1234567
1234568
C++ 允许单引号分隔数字以便于阅读:
https://en.cppreference.com/w/cpp/language/integer_literal
Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler.
自 C++14 起,
来自 https://en.cppreference.com/w/cpp/language/integer_literal
Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler.