从c++文件中读取链表
read linked list from file c++
我试图从文件中读取链表。但是由于某些原因,它甚至没有读取文件的内容。
这是文件的结构:
Product 1
Category
22.33
Product 2
Category
44.23
Product 3
Category
66.55
,这是读取文件内容的函数。它调用addproduct函数来按排序顺序添加它所读取的项。
void load (NodePtr head)
{
// create a variable to attach to the file
ifstream input;
input.open("data.txt");
// check to see if the file opened correctly, and if not, exit program
if (input.fail())
{
cout << "n Data file not found n";
return;
}
ListItemType data;
while((! input.eof()) && (head != NULL) )
{
input >> data.productname;
input >> data.category;
input >> data.productprice;
addproduct(head, data);
}
需要接收head的新指针。不是返回void,而是返回NodePtr.
NodePtr load( NodePtr head ){
...
return head;
}
相关文章:
- 将从格式化文本文件读取的文本数据存储到链表
- 尝试从单向链表C++中删除单个节点时出现读取访问冲突
- 在链表上写入和读取 fstream 的函数
- 如何从文件读取到动态分配的指向结构的指针链表中?
- C++链表读取访问冲突
- 从文件读取到链表中
- 将文本文件读取到双向链表并将其输出 - C++
- 将结构从二进制文件读取到链表,导致无限循环
- 存储类对象的C++模板链表-未处理的异常访问冲突读取位置
- 从文件读取链表C++从 void* 到 char* 的转换无效
- 想要读取超过 50,000 个 TXT 文件并将它们保存在 C++ 的链表中
- 通过在循环C++中从文件中读取文本来创建链表
- 在C++中读取链表上的访问冲突
- 正在从文件中读取中的数据并插入到链表C++中
- 将数据从文件读取到链表非常慢
- 在链表的开头插入时读取内存时出错
- 如何在c++中使用链表读取txt文件
- 从文件中读取,存储到链表中,然后再次打印到文件中
- 如何在文件中读取,其中包含char, int和空白到链表
- 从c++文件中读取链表