我对这个程序几乎感到沮丧。我有一个包含 100 条记录的文件,但我的输出不会超过 17 条,包括标题。谁能告诉我我做错了什么?
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
char medRecord[100][8];
int header, person;
int main()
{
ifstream in("fakedata.txt");
if(!in){
cout << "Cannot open file. \n";
return 1;
}
in.read((char *) &medRecord, sizeof medRecord);
for(person = 0; person < 100; person++)
for(header = 0; header < 8; header++)
cout << medRecord[person][header] << "";
return 0;
}
输出:
Number,Gender,GivenName,Surname,Birthday,BloodType,Pounds,FeetInches
1,male,Joseph,Doody,1/10/1968,A-,179.5,5' 7"
2,male,Robert,King,8/17/1985,A+,203.1,5' 10"
3,male,Richard,Murphy,3/18/1944,O+,235.6,6' 1"
4,female,Caroline,Acosta,5/27/1959,B+,145.4,5' 8"
5,male,John,Capps,12/18/1967,O+,186.6,5' 9"
6,female,Stephanie,Guidry,3/25/1981,O+,177.8,5' 6"
7,female,Janet,Kimmel,2/23/1977,A+,161.3,5' 7"
8,male,Jerrell,Wright,8/4/1929,B+,140.6,5' 9"
9,female,Cheryl,Johnson,12/8/1972,A+,128.7,5' 1"
10,female,Sandra,Gonzalez,6/1/1974,A+,171.4,5' 9"
11,male,Kevin,Noel,9/30/1939,O+,212.1,5' 6"
12,female,Krysta,Booth,7/9/1940,O+,173.1,5' 3"
13,male,Sam,Clark,7/5/1979,A+,162.4,5' 9"
14,male,James,Graves,8/15/1959,A+,235.0,5' 8"
15,male,Elton,Fink,6/30/1937,A+,198.4,5' 5"
16,male,Robert,Daniels,10/14/1969,Press any key to continue . . .