小编use*_*776的帖子

如何将 boost::iostreams::mapped_file_source 与 gzip 压缩的输入文件一起使用

我用来boost::iostreams::mapped_file_source从特定位置读取文本文件到特定位置并操作每一行(使用编译g++ -Wall -O3 -lboost_iostreams -o test main.cpp):

#include <iostream>
#include <string>
#include <boost/iostreams/device/mapped_file.hpp>

int main() {
    boost::iostreams::mapped_file_source f_read;
    f_read.open("in.txt");

    long long int alignment_offset(0);

    // set the start point
    const char* pt_current(f_read.data() + alignment_offset);
    // set the end point
    const char* pt_last(f_read.data() + f_read.size());
    const char* pt_current_line_start(pt_current);

    std::string buffer;

    while (pt_current && (pt_current != pt_last)) {
        if ((pt_current = static_cast<const char*>(memchr(pt_current, '\n', pt_last - pt_current)))) {
            buffer.assign(pt_current_line_start, pt_current - pt_current_line_start + 1);
            // do something with buffer …
Run Code Online (Sandbox Code Playgroud)

c++ boost gzip memory-mapped-files

5
推荐指数
1
解决办法
2311
查看次数

标签 统计

boost ×1

c++ ×1

gzip ×1

memory-mapped-files ×1