#include <iostream>
#include <fstream>
using namespace std;
#define MaxSize 150
typedef struct node
{
string num;
string name;
float price;
int count;
float sale;
int next;
}DataType;
typedef struct
{
DataType r[MaxSize+1];
int length;
}SequenList;
bool read(SequenList &L);
void displaysell(SequenList &L);
bool read(SequenList &L)
{
//读取文件中的数据
ifstream in("sell.txt");
int k=1;
while(1)
{
in>>L.r[k].num>>L.r[k].name>>L.r[k].price>>L.r[k].count>>L.r[k].sale;
if(L.r[1].num==" ")
{
cout<<"读取文件失败"<<endl;
return false;
}
if(L.r[k].num=="")break;
++k;
}
L.length=k-1;
cout<<"读取文件成功"<<endl;
cout<<k<<endl;
displaysell(L);
return 1;
}
void displaysell(SequenList &L)
{
cout<<"编号< "<<"名称< "<<"单价< "<<"销售量< "<<"销售额 "<<endl;
for(int k=1;k<=L.length;++k)
cout<<L.r[k].num<<" "<<L.r[k].name<<" "<<L.r[k].price<<" "<<L.r[k].count<<" "<<L.r[k].sale<<"\n"<<endl;
}
int main()
{
SequenList L;
read(L);
return 0;
}
文件编译没事但是文件读取总是读取不完
不懂为什么
#include <fstream>
using namespace std;
#define MaxSize 150
typedef struct node
{
string num;
string name;
float price;
int count;
float sale;
int next;
}DataType;
typedef struct
{
DataType r[MaxSize+1];
int length;
}SequenList;
bool read(SequenList &L);
void displaysell(SequenList &L);
bool read(SequenList &L)
{
//读取文件中的数据
ifstream in("sell.txt");
int k=1;
while(1)
{
in>>L.r[k].num>>L.r[k].name>>L.r[k].price>>L.r[k].count>>L.r[k].sale;
if(L.r[1].num==" ")
{
cout<<"读取文件失败"<<endl;
return false;
}
if(L.r[k].num=="")break;
++k;
}
L.length=k-1;
cout<<"读取文件成功"<<endl;
cout<<k<<endl;
displaysell(L);
return 1;
}
void displaysell(SequenList &L)
{
cout<<"编号< "<<"名称< "<<"单价< "<<"销售量< "<<"销售额 "<<endl;
for(int k=1;k<=L.length;++k)
cout<<L.r[k].num<<" "<<L.r[k].name<<" "<<L.r[k].price<<" "<<L.r[k].count<<" "<<L.r[k].sale<<"\n"<<endl;
}
int main()
{
SequenList L;
read(L);
return 0;
}
文件编译没事但是文件读取总是读取不完
不懂为什么