मुझे किसी फ़ंक्शन में फ़ाइल को पास करने के तरीके को समझने में कठिनाई हो रही है।फ़ंक्शन में फ़ाइल कैसे पास करें?
मेरे पास 20 नाम और 20 टेस्ट स्कोर वाली एक फ़ाइल है जिसे किसी फ़ंक्शन द्वारा पढ़ना आवश्यक है। फ़ंक्शन तब नाम और स्कोर को छात्र नामक संरचना में असाइन करेगा।
मेरा प्रश्न यह है कि मैं उपयुक्त पैरामीटर के साथ फ़ंक्शन कॉल कैसे लिखूं। ? मेरे फ़ंक्शन को फ़ाइल में डेटा पढ़ने के लिए। धन्यवाद।
कोड
// ask user for student file
cout << "Enter the name of the file for the student data to be read for input" << endl;
cout << " (Note: The file and path cannot contain spaces)" << endl;
cout << endl;
cin >> inFileName;
inFile.open(inFileName);
cout << endl;
// FUNCTION CALL how do i set this up properly?
ReadStudentData(inFile, student, numStudents);
void ReadStudentData(ifstream& infile, StudentType student[], int& numStudents)
{
int index = 0;
string lastName, firstName;
int testScore;
while ((index < numStudents) &&
(infile >> lastName >> firstName >> testScore))
{
if (testScore >= 0 && testScore <= 100)
{
student[index].studentName = lastName + ", " + firstName;
student[index].testScore = testScore;
index++;
}
}
numStudents = index;
}
आपके वर्तमान कोड के साथ आप क्या समस्या का सामना कर रहे हैं? मुझे लगता है कि, आप पैरामीटर को सही तरीके से पारित कर रहे हैं। – iammilind