如何在c++中使用链表读取txt文件
how to use linked list to read in txt file in c++
这是我到目前为止所拥有的,但这不会读取文本文件的未确定长度
#include <iostream>
#include <string>
#include <fstream>
using namespace std ;
int main()
{
char *file_name = "doc.txt" ;
ifstream fin ;
fin.open( file_name ) ;
if( ! fin ) {
cout << "Problems opening " << file_name << endl ;
return -1 ;
}
const unsigned MAX = 100 ;
string doc[MAX] ;
unsigned word_count = 0 ;
while( fin >> doc[ word_count ] )
{
cout << doc[ word_count ] << endl ;
word_count ++ ;
}
fin.close() ;
return 0 ;
}
您可以使用矢量并将新单词推到上面。
如果你只是推和弹出,堆叠会更快。
或者,总有清单。
这在很大程度上取决于你在做什么,以及速度是否重要。
相关文章:
- 将从格式化文本文件读取的文本数据存储到链表
- 尝试从单向链表C++中删除单个节点时出现读取访问冲突
- 在链表上写入和读取 fstream 的函数
- 如何从文件读取到动态分配的指向结构的指针链表中?
- C++链表读取访问冲突
- 从文件读取到链表中
- 将文本文件读取到双向链表并将其输出 - C++
- 将结构从二进制文件读取到链表,导致无限循环
- 存储类对象的C++模板链表-未处理的异常访问冲突读取位置
- 从文件读取链表C++从 void* 到 char* 的转换无效
- 想要读取超过 50,000 个 TXT 文件并将它们保存在 C++ 的链表中
- 通过在循环C++中从文件中读取文本来创建链表
- 在C++中读取链表上的访问冲突
- 正在从文件中读取中的数据并插入到链表C++中
- 将数据从文件读取到链表非常慢
- 在链表的开头插入时读取内存时出错
- 如何在c++中使用链表读取txt文件
- 从文件中读取,存储到链表中,然后再次打印到文件中
- 如何在文件中读取,其中包含char, int和空白到链表
- 从链表的末尾开始读取值,而不是从开头