【发布时间】:2016-08-14 00:56:51
【问题描述】:
我只是在学习 c++ 并试图理解数组。所以请原谅我对这里出了什么问题的无知。
#include <iostream>
#include <string>
#include <array>
using namespace std;
void readArray(int *readfile, int ArraySize){
int Interator;
for(Interator = 1; Interator < ArraySize; Interator++){
cout << " " << readfile[Interator];
}
}
int main(){
std::array<int, 5> array2={{1, 2, 3, 4, 5}};
readArray(array2, array2.end());
}
错误:无法将 'std::array' 转换为 'int*' for arg '1' to void 'readArray'
我该如何解决这个问题?
【问题讨论】:
-
有很多错误,例如 readArray 使用指针作为第一个参数,并且您通过值而不是通过引用传递。 end() 指向数组的最后一项,而不是实际大小。