Click here to Skip to main content
15,887,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So, I'm using the Eigen matrix library (version 3.3.7), and I'm trying to test things out and see that everything's going fine. However, on the test program below:

What I have tried:

C++
#include <iostream>
#include <sstream>

#include <Eigen/Dense>

using namespace std;
using namespace Eigen;

int main()
{
	cout << "Hello World!" << endl;

	MatrixXd A;
	A << 1, 2, 3,
		4, 5, 6,
		7, 8, -9;

	cout << A << endl;

	cin.get();
	return 0;
}


I'm getting an error:

<pre>"Exception thrown at 0x________ in Matrices.exe: 0xC0000005: Access violation writing location 0x00000000."


Oddly enough, everything goes fine if I initialise a Matrix3d instead of a MatrixXd. Could anyone help me and figure out how to fix this?
Posted
Updated 28-Mar-19 15:26pm
v2
Comments
MadMyche 28-Mar-19 20:08pm    
How are you compiling this?
uarc40960 28-Mar-19 20:39pm    
Visual Studio

1 solution

This works for me:
C++
Eigen::MatrixXd a( 3, 3 );
a << 1, 2, 3,
     4, 5, 6,
     7, 8, 9;

std::stringstream s;
s << a;

trace( "%s\n", s.str().data() );
trace is the output function I use in my apps. The issue is MatrixXd is a dynamic matrix and you have to tell it how big the matrix is first.
 
Share this answer
 
Comments
uarc40960 28-Mar-19 21:43pm    
Thanks SO MUCH!
Maciej Los 29-Mar-19 13:30pm    
5ed!
Rick York 29-Mar-19 14:00pm    
Thank you sir.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900