The io module provides a simple, modern, and cross-platform API for working with input and output streams in C++.
It is designed to be:
- simple to use
- lightweight
- consistent
- familiar for developers coming from Node.js, Deno, or Bun
I/O in Vix follows strict principles:
- simple functions, no boilerplate
- explicit error handling (
Result<T>) - stream-first design
- no unnecessary abstractions
- composable APIs
The goal is to bring a modern developer experience to C++ I/O.
Using Vix:
vix add @vix/io#include <vix/io/Io.hpp>
int main()
{
auto out = vix::io::stdout_stream();
vix::io::write_line(out, "Hello Vix IO");
}auto in = vix::io::stdin_stream();
auto out = vix::io::stdout_stream();
auto err = vix::io::stderr_stream();auto line = vix::io::read_line(in);
if (line)
{
vix::io::write_line(out, line.value());
}auto data = vix::io::read_all(in);
if (data)
{
vix::io::write(out, data.value());
}auto chunk = vix::io::read(in, 1024);vix::io::write(out, "Hello");
vix::io::write_line(out, " world");vix::io::Bytes bytes{65, 66, 67};
vix::io::write(out, bytes);vix::io::flush(out);auto result = vix::io::copy(in, out);
if (!result)
{
vix::io::write_line(err, "copy failed");
}vix::io::Buffer buffer;
buffer.append("Hello ");
buffer.append("Buffer");
vix::io::write_line(out, buffer.to_string());vix::io::IoOptions options;
options.chunk_size = 8192;
options.auto_flush = true;Used in:
- read_all()
- write_line()
- copy()
All operations return a Result<T>.
auto result = vix::io::read_line(in);
if (!result)
{
std::cerr << result.error().message() << "\n";
return;
}using Bytes = std::vector<std::uint8_t>;vix::io::Buffer buffer;
buffer.append("data");See the examples/ directory:
- basic.cpp
- stdin.cpp
- stdout.cpp
- read_all.cpp
- buffer.cpp
- copy_stream.cpp
- advanced.cpp
iois stream-orientedfshandles filesystem (files, directories)iohandles streams (stdin, stdout, buffers)- no exceptions required
- simple and composable API
Traditional C++ I/O:
- verbose
- inconsistent
- hard to compose
Vix IO provides:
- simple APIs
- predictable behavior
- structured errors
- modern developer experience
MIT License