将Eigen中的Matrix放到mfc的Eidt Control控件上,并实现滚动换行等
核心的思路是通过stringstream类进行操作,先将Eigen::Matrix4d 类的对象T传入流,然后再利用流将其传给字符串string,之后再将类型改为CString
//头文件
#include<assert.h>
#include <fstream>
#include <sstream>
#include <iomanip>
//核心代码
string res;
res += "矩阵T为:\r\n";
std::stringstream stream;
stream << T;
string suanz;
while (getline(stream, suanz)) {
res += suanz;
//在mfc的edit控件中换行符为"\r\n"而不是单纯的“\n”
res += "\r\n";
}
CString cstr;
cstr = res.c_str();
SetDlgItemText(IDC_EDIT7, cstr);
注意:
- 在mfc的edit控件中换行符为"\r\n"而不是单纯的“\n”
- 要在edit control的属性上的一下四项的值改为true