[英]Reading a large text file to memory in C++
Is there a way to read a large text file (~60MB) into memory at once (like a compiler flag to increase program memory limit) ? 有没有一种方法可以一次将大文本文件(〜60MB)读入内存(例如增加程序内存限制的编译器标志)? Currently, ofstream's open function throws a segmentation fault while trying to read this file.
当前,ofstream的open函数在尝试读取此文件时引发分段错误。
ifstream fis;
fis.open("my_large_file.txt"); // Segfaults here
The file just consists of rows of the form 该文件仅由表格的行组成
number_1<tabspace>number_2
ie, two numbers separated by a tabspace. 即,两个数字之间用制表符分隔。
You have some other problem, because you aren't reading the file by just calling open
. 您还有其他问题,因为您不是通过调用
open
读取文件。 My guess is the file doesn't exist (or doesn't exist in the relative path you think it should exist in). 我的猜测是文件不存在(或在您认为应该存在的相对路径中不存在)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.