ifstream最好的方式来读取没有内存使用 [英] ifstream best way to read without memory usage

查看:1059
本文介绍了ifstream最好的方式来读取没有内存使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含作者和作者写的书的文本文件。我被分配写一个程序,用户将提供作者的名字。并且程序必须打印作者写的任何书的名称。

I have a textfile that contains authors and the books written by authors. I am assigned to write a program in that the user will provide the name of a author. And the program must print the name of any books written by that author.

我理解我应该使用ifstream读取这些信息。但是如何才能使我的程序不会将整个文件读入内存(数组,向量等)以执行任何搜索查询?

I understand that i am supposed to use an ifstream to read this information. But how can i make it so my program doesn't read the entire file into memory (array, vector, etc.) to perform any of the search queries?

最好的方法是什么?我的程序也应该使用类。

What would be the best way to approach this? my program should use classes as well.

推荐答案

我不知道整个答案,方式开始是你知道的输入文本文件的格式是什么?它只是一个两列文件,如:[作者Book]用公共分隔符分隔?在这种情况下,您可以构造一个遍历整个文件的循环,并将条目存储到与搜索字符串匹配的向量中。

I don't know the whole answer, or even the syntax, but a good way to get started is what do you know about the format of the input text file? Is it simply a two-column file like: [Author Book] separated by a common delimiter? In that case, you could construct a loop that goes through the whole file and only store the entries into a vector that match the search string.

这篇关于ifstream最好的方式来读取没有内存使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆