我正在尝试使用Eigen库学习C++.
int main(){
MatrixXf m = MatrixXf::Random(30,3);
cout << "Here is the matrix m:\n" << m << endl;
cout << "m" << endl << colm(m) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如何导出m
到文本文件(我搜索过文档但没有找到写入功能)?
coo*_*451 15
如果你可以在cout上编写它,它适用于任何std :: ostream:
#include <fstream>
int main()
{
std::ofstream file("test.txt");
if (file.is_open())
{
MatrixXf m = MatrixXf::Random(30,3);
file << "Here is the matrix m:\n" << m << '\n';
file << "m" << '\n' << colm(m) << '\n';
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16996 次 |
最近记录: |