This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Printing a matrix of unsigned bytes (uint8_t) as numbers

Tags: None
(comma "," separated)
User avatar
fasih
Registered Member
Posts
3
Karma
0
Code: Select all
typedef Eigen::Matrix<uint8_t, Dynamic, Dynamic> MatrixXuint8;
MatrixXuint8 tmp(2, 3);
tmp << 51, 52, 53, 54, 55, 56;
cout << "tmp is: " << dec << tmp << endl;

This code, which creates a matrix of unsigned bytes, prints it as ASCII:
tmp is: 3 4 5
6 7 8

I thought the `dec` would instruct Eigen/C++ to give me a decimal interpretation of the values but no luck. I don't see anything in IOFormat that'll control this aspect of the printout. How can I get this to print out numbers the way MatrixXi would?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
std::dec does not change how char are printed, regardless of Eigen. So as a workaround you have to cast it like: cout << tmp.cast<short>()


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]