Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no way to output vector<uint8_t> such as vectors #136

Closed
heheda123123 opened this issue Jun 27, 2024 · 3 comments
Closed

There is no way to output vector<uint8_t> such as vectors #136

heheda123123 opened this issue Jun 27, 2024 · 3 comments

Comments

@heheda123123
Copy link

if i use below code

#include <iostream>
#include <vector>
#include <iomanip>  // For std::hex and std::setw

std::ostream& operator<<(std::ostream& out, const std::vector<uint8_t>& v) {
    for (const auto& val : v) {
        // Output each value in hexadecimal format, padded with zeros to 2 digits
        out << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(val) << " ";
    }
    return out;
}


int main() {
  std::vector<uint8_t> aa {1,2,3};
  std::cout << aa;

  return 0;
}

output is

01 02 03

if I use dbg-macro, the output is



#include <iostream>
#include <vector>
#include <iomanip>  // For std::hex and std::setw
#include <dbg.h>

std::ostream& operator<<(std::ostream& out, const std::vector<uint8_t>& v) {
    for (const auto& val : v) {
        // Output each value in hexadecimal format, padded with zeros to 2 digits
        out << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(val) << " ";
    }
    return out;
}


int main() {
  std::vector<uint8_t> aa {1,2,3};
  dbg(aa);

  return 0;
}
[src\main.cpp:19 (main)] aa = {, , } (std::vector<uint8_t>)
@heheda123123
Copy link
Author

can use this method

  dbg(std::vector<uint32_t> (aa.begin(), aa.end()));

@sharkdp sharkdp reopened this Jun 30, 2024
@sharkdp
Copy link
Owner

sharkdp commented Jun 30, 2024

Thank you for reporting this. I'll actually reopen this. Would be great if we could support this out-of the box.

@heheda123123
Copy link
Author

the example code in #137 will solve this problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants