如何在C++中使用带变量的科学记数法?

Mil*_*d R 2 c++ notation

我想知道是否可以使用带变量的科学记数法?

例如:

int n;
cin >> n;
int x = 1en;
Run Code Online (Sandbox Code Playgroud)

代替

int x = 1e8
Run Code Online (Sandbox Code Playgroud)

可能吗?如果有,怎么样?

Zet*_*eta 6

不可以.科学记数法仅适用于恒定值.这些值在编译时确定,而您想要获取的值在运行时确定.

你必须使用类似的东西int result = pow(10,n).请记住,std::pow返回double值.