gpt4 book ai didi

c++ - 错误 : No matching function for call to memsetNincr

转载 作者:行者123 更新时间:2023-11-30 02:34:54 25 4
gpt4 key购买 nike

函数 memsetNin​​cr 是用整数填充大小为“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/

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