0
텍스트 파일에서 정보를 가져 와서 내가 만든 구조체에 넣은 다음 배열을 표시하는 데 문제가 있습니다. 지금까지 구조체를 만들고 매개 변수를 사용하여 함수를 만들었지 만 작동하지 않는 것 같습니다. 저를 올바른 방향으로 인도 할 수 있다면, 좋을 것입니다. struct로 txt 파일 읽기 및 배열 표시
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int N=5;
struct RECORD
{
char *Name;
int Age;
float Gpa;
};
void CopyRecords (string filename, int p[N]);
void Display (RECORD x[]);
int main()
{
RECORD p[N];
//Read data from this file into array p
CopyRecords("data2.txt", p);
//Display all records
Display(p);
//Terminate Program
system ("pause");
return 0;
}
void CopyRecords (string filename, int p[N])
{
ifstream f;
f.open(filename, ios::in);
for(int i = 0; i <= N; ++i)
{
f >> p[i];
}
}
void Display (RECORD x[])
{
for (int i = 0; i < N; ++i)
cout << x[i].Name << " " << x[i].Age << " " << x[i].Gpa << endl;
}
이
은Martin Smith/ 22 2.2
Austin Clinton/ 18 3.1
Johnson/ 19 2.9
Maggie Jones/ 23 2.3
Tyler W Brown/ 16 3.4