Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
804 B
4
Indexable
#include <asio/io_context.hpp>
#include <asio/random_access_file.hpp>
#include <asio/stream_file.hpp>
#include <iostream>
#include <string>

using namespace asio;

void test_async_read() {
  asio::io_context ioc;
  //try {
    stream_file file(ioc, "/home/he/read_some_test/main.cc", stream_file::read_only); // the file exists and has contents.
    
    char data[128]= {};
    file.async_read_some(buffer(data),
                         [data](asio::error_code ec, size_t size) {
                           std::cout << ec.message() << " " << size << "\n";
                         });
    ioc.run();
    //std::cout << data << std::endl;
  //} //catch (std::exception &e) {
    //std::cout << e.what() << "\n";
  //}
  std::cout << data << std::endl;
}

int main(int, char **) {
  test_async_read();
}