我想把一个像5个变量的列表放在一个列表中.
例如:
int i = 6;
int a = 5;
int b = 1;
int x = 9;
int z = 4;
int num = i && a && b && x && z;
cout << num;
Run Code Online (Sandbox Code Playgroud)
我想要num来显示这个数字:65194
对于数字,您可以使用基本算术:
int num = ((((i * 10) + a) * 10 + b) * 10 + x) * 10 + z;
Run Code Online (Sandbox Code Playgroud)
只需使用一个 std::vector
然后使用std::vector::push_back将元素插入其中.
std::vector<int> my_vector;
my_vector.push_back(6);
my_vector.push_back(5); // push the rest of the numbers
Run Code Online (Sandbox Code Playgroud)
要显示内容:
for(auto& i: my_vector)
std::cout << i;
Run Code Online (Sandbox Code Playgroud)