libzed 1.9.9
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
lines.cpp
// This is an example of using the z::file::lines() generator to read a file line-by-line.
// This is a memory-efficient way of reading large files, as the data is only loaded as needed.
// z::file::lines(zstring& filename) // z::file::lines(std::istream &stream)
#include <iostream>
#include <z/file.hpp>
int main() {
zstring filename = execdir() + "/../data/in1.txt";
("Printing all lines in "_zs + filename).writeln(std::cout);
for (auto line : lines(filename)) {
line.writeln(std::cout);
}
}
A template class for character strings.
Definition string.hpp:62
void writeln(std::ostream &stream) const noexcept
Write string data to a stream in its format, appending a newline.
Definition string.hpp:1507
zpath execdir() noexcept
Get the directory path of the running executable.
Definition execdir.hpp:11
core::generator< zstring, fileHandle > lines(const zpath &filename)
Reads the contents of a file line-by-line.