C++如何将int附加到int?

use*_*097 1 c++ int append

如何将int附加到int:

x = 23;
y = 54;

result = 2354;
Run Code Online (Sandbox Code Playgroud)

我希望你帮助我.

use*_*740 5

以下是两种常规方法:

  1. 通过乘以适当的10的幂来"左移"左整数,然后添加正整数.在注释中显示的x * 100 + y(或x * pow(10,2) + y)示例代码中.

    要转移的值可以从正确数字的log 10的上限得出.使用上面的数学,这可以更广泛地扩展为x * pow(10, ceil(log10(y))) + y.

  2. 将整数转换为字符串,连接字符串,并将结果字符串转换回整数.