相关疑难解决方法(0)

在VC++中读取一个boost内存映射文件的结尾

我正在使用VS2010编写一个C++程序来读取文本文件并从中提取某些信息.我使用filestream完成了代码,效果很好.但是现在我被要求将文件映射到内存并使用它而不是文件操作.

在内存映射的情况下,我绝对是一个新手.我写的代码的一部分如下.

boost::iostreams::mapped_file_source apifile;

apifile.open(LogFileName,LogFileSize);

if(!apifile.is_open()) 

return FILE_OPEN_ERROR;

// Get pointer to the data.

PBYTE Buffer = (PBYTE)apifile.data();

while(//read till end of the file)
{
     // read a line and check if it contains a specific word
}
Run Code Online (Sandbox Code Playgroud)

在使用FILESTREAM我会用eofgetlinestring::find用于执行操作.但我不知道如何使用内存映射文件来做到这一点.

编辑1:

int ProcessLogFile(string file_name)
{
    LogFileName = file_name;

    apifile.open(LogFileName);//boost::iostreams::mapped_file_source apifile(declared globally)

    streamReader.open(apifile, std::ios::binary);//boost::iostreams::stream <boost::iostreams::mapped_file_source> streamReader(declared globally)

    streamoff Curr_Offset = 0;

    string read_line;

    int session_id = 0;

    int device_id = 0;

    while(!streamReader.eof())
    {
        \\COLLECT OFFSETS OF …
Run Code Online (Sandbox Code Playgroud)

c++ memory boost visual-studio-2010

6
推荐指数
1
解决办法
6143
查看次数

std::spanstream 通常如何在 C++ 中使用?

<spanstream>将在 C++23 中首次亮相(请参阅cppreference)。根据提案,它们是std::span基于缓冲区的字符串流。

我的问题是:

  • 是否std::spanstream与旧的std::strstream(或strstream在 C++ 98 中已弃用)有些等效?
  • 在 C++ 23 完全发布后使用它们有什么好处?

c++ strstream c++23

3
推荐指数
1
解决办法
144
查看次数

标签 统计

c++ ×2

boost ×1

c++23 ×1

memory ×1

strstream ×1

visual-studio-2010 ×1