各位高手帮我看一下这段代码哪里有问题,谢谢!

来源:百度知道 编辑:UC知道 时间:2024/07/04 11:57:42
#include <iostream>
#include <string>
#include <stdlib.h>
#include <string>
#include <fstream>
using namespace std;

struct Medicine
{
int ID; //ID号
string name; //药品名称
string category; //药品类别
int ids; //药品批准文号
string company; //生产企业
int month; //有效期
int date_year; //年
int date_month; //月
int date_day; //日
Medicine *pNext;
};

Medicine* pHead=NULL;

void LoadMedicine()//读取文件函数
{
int ID;
char name[50];
char category[50];
int ids;
char company[50];
int month;
int date_year;
int date_month;
int date_day;

ifstream inf("e:\\1.txt");//读取文件数据

Medicine* pTemp = new Medicine;
if (!inf)
{
cout<<"Can't open the file!"<<endl;
return;
}
inf>>ID;

不清楚的话,可以HI我。
inf>>ID;//每个数据单独一行
inf.ignore(100, '\n'); //跳过输入流中的换行
inf.getline(name, 50);
inf.getline(category, 50);
inf>>ids;
inf.ignore(100, '\n');//跳过输入流中的换行
inf.getline(company, 50);
inf>>month>>date_year>>date_month>>date_day;

pTemp->ID=ID;
pTemp->name=name;
pTemp->category=category;
pTemp->ids=ids;
pTemp->company=company;
pTemp->month=month;
pTemp->date_year=date_year;
pTemp->date_month=date_month;
pTemp->date_day=date_day;

pTemp->pNext = NULL; //后向指针要赋值为空

好像是对的把,我怎么看不出哪里错了,可能是你电脑的问题

你把你编译时,提示出错的信息拿出来。。。

如果编译没错,你把运行中的具体问题说说。。。

光看程序,好像是对的。。。

你这是在程序中少了一句设置状态的语句,编译语法上没问题,所以在运行中由于其状态不能读,所以你应该先用一个函数将其设为“打开状态”。。。

我以前编程时也常碰到这个问题。。。

没有错误