0

I am trying to retrieve data from boost array with Bytes data which should at the end be 2 double. I don't why but I can't make the conversion of the buffer to a readable format here is my attempt :

boost::array<void*, 1024> arr;
boost::system::error_code error_2;
socket_2.read_some(boost::asio::buffer(arr), error_2);  
for (int k = 0; k < 32; k++) { std::cout << arr[k]; }

I don't understand how to retrieve the data from arr, memcpy is not accepted for instance.

2
  • Please read the tour to the end, and inform yourself at our help center what and how you can ask here! Commented Sep 19, 2022 at 16:59
  • You are passing an array of void pointers and expecting some kind of readable buffer in return? Commented Sep 19, 2022 at 16:59

1 Answer 1

1

Effectively, whatever you do will amount to memcpy. But you can make things more elegant:

boost::array<double, 4096 / sizeof(double)> arr;

boost::system::error_code ec;

size_t n = s.read_some(asio::buffer(arr), ec);

for (size_t i = 0; i < (n / sizeof(double)); ++i) {
    std::cout << arr[i];
}

If you already have a raw buffer, consider asio::buffer_cast<>

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thank you, it works, I retrieve the info, thank you, I am sorry for the misteake, I was not able to identify what was wrong..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.