Search⌘ K
AI Features

Converting Lines into Records

Explore how to efficiently convert a file's lines into records by using C++17 features like string_view. Understand the process of reading entire file content into a string and splitting it into views to avoid data copying, preparing the data for further processing.

We'll cover the following...

LoadRecords is a function that takes a filename as an argument, reads the contents into std::string and then performs the conversion:

C++
[[nodiscard]] std::vector<OrderRecord> LoadRecords(const fs::path& filename)
{
const auto content = GetFileContents(filename);
const auto lines = SplitLines(content);
return LinesToRecords(lines);
}

We assume ...