新手求助,c++一个关于线性链表的问题
#include <iostream>
#include <fstream>
#include<cstdio>
#include<malloc.h>
#include<string.h>
#include <stdlib.h>
using namespace std;
typedef struct LNode
{
string line;//数据是一组字符串
struct LNode *next;
}LNode,*LinkList;
void Createlist_L(LinkList &L,int n)//n为链表长度
{
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
LinkList p,q=L;
ifstream ifs("stock11.txt");//该文件中存储了18组数据,每组一行
for(int i=1;i<=n;++i)
{
p=(LinkList)malloc(sizeof(LNode));
getline(ifs,p->line);
cout<<i<<endl;//调试语句
cout<<p->line<<endl;//调试语句
q->next=p;p->next=NULL;q=q->next;
}
ifs.close();
}
int main()
{
LinkList L;
Createlist_L(L,100);
return 0;
}