在我的项目中包括eigen将标准INT定义为eigen :: denseIndex-如何使用正常INT

Including Eigen in my project redefines the standard int to Eigen::DenseIndex - how to use the normal ints?

本文关键字:eigen INT denseIndex- 我的 何使用 定义 项目 包括 标准      更新时间:2023-10-16

我正在尝试创建一个向量来输入.txt文件的某些数据,但是我得到错误:

no operator ">>" matches these operands
operand types are: std::ifstream >> std::vector<Eigen::DenseIndex, std::allocator<Eigen::DenseIndex>>

我的代码是:

dataIn.open("data.txt");
vector<int> hnew;
dataIn >> hnew;
dataIn.close();

data.txt只是空间分离ints的长量向量。我该怎么办?

eigen :: denseIndex只是int的类型别名。这不是问题。

编译器警告您没有超载

template <typename T, typename A>
std::istream & operator >>(std::istream &, std::vector<T. A> &)

默认情况下没有提供。您可以使用istream_iterator构造这样的hnew:

dataIn.open("data.txt");
vector<int> hnew(istream_iterator<int>(dataIn), istream_iterator<int>());