我试图显示名为vector
的{{1}}内容,但我收到此错误消息:
错误:表达式在尝试匹配参数列表时必须具有类类型'(std :: ostream,std :: vector< long,std :: allocator< _Ty>>)
我不明白为什么我会遇到这个错误。这是我的代码:
l_anMarking
class SPSIM_EXPORT ParaStochSimulator : public StochasticSimulator
{
private:
protected:
VectorLong m_anCurrentMarking;
long m_nMinTransPos;
public:
void first_reacsimulator();
void ParaStochSimulator::broad_cast(long);
}
答案 0 :(得分:0)
您的l_anMarking
变量被声明为原始double*
指针,但您尝试通过调用begin()
和end()
将其视为STL容器。因此编译错误。
您有两种选择:
更改第二个for
循环以使用索引而不是迭代器。
for (int k = 0; k < i; ++k)
{
std::cout << l_anMarking[k] << std::endl;
}
相应地将l_anMarking
更改为std::vector<double>
(并相应地调整MPI_Bcast()
):
std::vector<double> l_anMarking;
l_anMarking.reserve(l_nMinplacesPos.size());
for (auto lnpos : l_nMinplacesPos)
{
val = m_anCurrentMarking[lnpos];
l_anMarking.push_back(val);
}
for (auto marking : l_anMarking)
{
std::cout << marking << std::endl;
}
答案 1 :(得分:-1)
编译器错误是指无法将VectorLong打印到std :: cout
std::vector<VectorLong>::iterator it;
for (it = l_anMarking.begin(); it < l_anMarking.end(); it++) //here
{
std::cout << *it << std::endl; // need an operator<< for your VectorLong
}
您应该添加以下内容:
std::ostream & operator<<(std::ostream &os, const VectorLong& v)
{
os << "VectorLong: ";
for (const auto &l : v)
os << l << " ";
return os;
}