我正在努力解决这部分代码,无论我尝试什么,我都不能让它读取两行之后的记录
文本文件包含
Mickey Mouse 12121 Goofy 24680 Andy Capp 01928 Quasi Modo 00041 end
而代码是
#include<iostream>
#include<string.h>
#include <stdio.h>
#include <windows.h>
#include<iomanip>
#include<conio.h>
#include<fstream>
#include<string>
using namespace std;
struct record
{
char name[20];
int number;
};
void main()
{
record credentials[30];
int row=0;
fstream textfile;//fstream variable
textfile.open("credentials.txt",ios::in);
textfile.getline (credentials[row].name,30);
//begin reading from test file, untill it reads end
while(0!=strcmp(credentials[row].name,"end"))
{
textfile>>credentials[row].number;
row++;
//read next name ....if its "end" loop will stop
textfile.getline (credentials[row].name,30);
}
textfile.close();
}
Run Code Online (Sandbox Code Playgroud)
记录只采取前两行,其余的是空的任何想法?