我收到错误:
expected primary-expression before ']' token`
在这一行:
berakna_histogram_abs(histogram[], textRad);
有人知道为什么吗?
const int ANTAL_BOKSTAVER = 26; //A-Z
void berakna_histogram_abs(int histogram[], int antal);
int main() {
string textRad = "";
int histogram[ANTAL_BOKSTAVER];
getline(cin, textRad);
berakna_histogram_abs(histogram[], textRad);
return 0;
}
void berakna_histogram_abs(int tal[], string textRad){
int antal = textRad.length();
for(int i = 0; i < antal; i++){
if(textRad.at(i) == 'a' || textRad.at(i) == 'A'){
tal[0] + 1;
}
}
}
最佳答案
main()中函数调用错误:
berakna_histogram_abs(histogram[], textRad);
应该是:
berakna_histogram_abs(histogram, textRad);
你只需要在函数声明中使用[]
,而不是在调用函数时。
关于c++ - 错误 : expected primary-expression before ']' token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18420334/