C++: Print Eigen::Quaterniond Values to Console
Problem: I have a project where I’m using the Eigen library’s Quaterniond structure. I’ve initialized the values, but now I want to see what those values are by printing them to the console using std::cout. However, everytime I try something like this
std::cout << “Debug: ” << “myQuaternion = ” << myQuaternion << std::endl;
I get an error like this:
error: invalid operands to binary expression (‘basic_ostream
std::__1::char_traits >’ and ‘Eigen::Quaterniond’ (aka‘Quaternion ’))
How do I print my Eigen::Quaterniond’s values to the console?
Solution: To print the Quaternion’s values to the console, you have to print each value individually. Recall that you can access the Quaternion’s scalar with myQuaternion.w() and the vector with myQuaternion.vec().
Thus, you just have to print out these vals individually like so: