我有一个任务要从文件“numbs.txt”中提取整数列表。这些数字是 1-200 之间的随机数。然后,我需要将它们分成 25 个范围(0-24、25-49...),并报告每个数字范围内的 man 整数。当我试图取回整数列表时,我迷路了。我试图将它们输入到另一个数组中,希望我可以计算新数组中的整数。我刚刚学习 C++ 中的函数和数组,因此非常感谢您的帮助。
从“int”到“int*”的无效转换[-fpermissive]是我尝试调用函数时收到的消息。
#include<iostream>
#include<array>
#include<fstream> // open, read, and close files
using namespace std;
ifstream grades;
string grade_file = "numbs.txt";
const int SCORE_SIZE = 26;
int scores[SCORE_SIZE];
void getNumbs();
int * score_count(int s_count[]);
//void getNumbs(int scores[], int scoreSize);
int main() {
getNumbs();
cout << "The following array positions are scores below 24 file: " << endl;
int s_count[] = score_count(scores[a]); << invalid conversion from 'int' to 'int*' [-fpermissive]
return 0;
}
void getNumbs(){
ifstream grades; // input file variable
string grade_file = "numbs.txt"; // inpute file name variable
cout << "Opening File." << endl; // update
grades.open(grade_file.c_str()); // opening file
if (grades.is_open()){ // Verifying file is open
cout << grade_file << " Is Open." << endl;
for(int i = 0; i < SCORE_SIZE; i++){ // If file is open iterate through the numbers and enter them into string array
grades >> scores[i];
cout << scores[i] << " ";
}
}
else {
cout << "No file found: " << grade_file << endl;
}
grades.close(); // Close file
cout << "\nFile is closed." << endl;
cout << endl;
}
// function to separate the numbers between 0 - 24.
int * score_count(int s_count[]){
for (int a = 0; a < SCORE_SIZE; a++){
if (scores[a] <= 24){
cin >> s_count[];
}
return s_count[];
}
}
您的程序似乎存在以下一些问题:
请解决这些问题。