小编Mic*_*key的帖子

如何将文件传递给函数?

我很难理解如何将文件传递给函数.

我有一个20个名字和20个测试分数的文件,需要由一个函数读取.然后,该函数将名称和分数分配给名为student的结构.

我的问题是如何使用适当的参数编写函数调用.?使我的函数读取文件中的数据.谢谢.

码

// 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, …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

5
推荐指数
1
解决办法
4万
查看次数

标签 统计

c++ ×1

visual-c++ ×1