> "匹配这些操作数-6ren"> > "匹配这些操作数-我正在编写一个函数定义,让用户输入数组的元素,但出现错误 cin >> a[index]; void show(const double a[], unsigned els) { size_t-6ren">
gpt4 book ai didi

c++ - 没有运算符 ">> "匹配这些操作数

转载 作者:太空狗 更新时间:2023-10-29 23:50:02 28 4
gpt4 key购买 nike

我正在编写一个函数定义,让用户输入数组的元素,但出现错误 cin >> a[index];

void show(const double a[], unsigned els) {
size_t index = 0;

for (index = 0; index < els; index++) {
cin >> a[index];
}

for (index = 0; index < els; index++) {
if (a[index] == a[0]) {
cout << "{" << a[index] << ",";
}
else if (a[index] == a[els - 1]) {
cout << a[index] << "}";
}
else { cout << a[index] << ","; }
}
cout << endl;
}

最佳答案

在您复制的代码中查看我的注释:

void show(const double a[], unsigned els) {  // a is const
size_t index = 0;

for (index = 0; index < els; index++) {
cin >> a[index]; // you're trying to write to a const array
}

关于c++ - 没有运算符 ">> "匹配这些操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34301353/

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