gpt4 book ai didi

c++ - 拼接问题

转载 作者:行者123 更新时间:2023-11-27 23:42:14 26 4
gpt4 key购买 nike

我想获取三个用户输入值 A、B、C,然后创建一个新的整数来存储这三个值,称为容量。我希望整数用逗号分隔,但是当我输出整数容量时,它仅作为 C 的值返回。我不知道如何解决这个问题。

#include <iostream>

using namespace std;

int main()
{
int A;
cout <<"Enter Capacity of Jug A"<< endl;
cin >>A;
int B;
cout <<"Enter Capacity of Jug B"<< endl;
cin >>B;
int C;
cout <<"Enter Capacity of Jug C"<< endl;
cin >>C;

int capacity;
capacity = (A, B, C);
cout <<"capacity is "<< capacity;

return 0;
}

最佳答案

你可以像这样使用数组:

#include <iostream>

using namespace std;

int main()
{
int A;
cout << "Enter Capacity of Jug A" << endl;
cin >> A;

int B;
cout << "Enter Capacity of Jug B" << endl;
cin >> B;

int C;
cout << "Enter Capacity of Jug C" << endl;
cin >> C;

int capacity[3];
capacity[0] = A;
capacity[1] = B;
capacity[2] = C;

cout << "capacity is " << capacity[0] << "," << capacity[1] << "," << capacity[2];

return 0;
}

关于c++ - 拼接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53685113/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com