作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
函数 memsetNincr 是用整数填充大小为“size”的数组,每个整数的值都比最后一个大 1。我最近在函数方面遇到了这个问题......
#include <iostream>
using namespace std;
void memsetNincr(int, int, int);
int main()
{
int size, initVal;
cout << "Enter size of array followed by the value of its' first element: \n";
cin >> size >> initVal;
int array[size];
cout << memsetNincr(array, size, initVal) << endl;
return 0;
}
void memsetNincr(int array[], int howmany, int startingVal)
{
int i;
array[0] = startingVal;
for (i=0; i<=howmany; i++)
{
array[i] = array[i-1]-1;
cout << array[i] << " ";
}
}
最佳答案
cout
需要一个流或可以转换为流的东西。您的函数返回 void,并且无法强制转换 void。要么更改函数以返回字符串或字符串流对象,要么在 cout 外部调用它。
编辑:在 cout
之外调用它,我的意思是这样的:
int main()
{
int size, initVal;
cout << "Enter size of array followed by the value of its' first element: \n";
cin >> size >> initVal;
int array[size];
memsetNincr(array, size, initVal);
cout << endl;
return 0;
}
关于c++ - 错误 : No matching function for call to memsetNincr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34219302/
我是一名优秀的程序员,十分优秀!