Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用函数通过向量迭代器获得前5个值_C++_Vector - Fatal编程技术网

C++ 使用函数通过向量迭代器获得前5个值

C++ 使用函数通过向量迭代器获得前5个值,c++,vector,C++,Vector,嗨,当我在函数本身中使用向量迭代器时,我遇到了编译错误 我试着从中执行这个例子,效果非常好。然而,当我试图把它放在一个函数中时,事情变得很糟糕,为什么会这样 vector <PointTwoD> topfive; void MissionPlan::topfives() { topfive.assign( point1.begin(), point1.end() ); sort(topfive.begin(), topfive.end(), sortByCiv

嗨,当我在函数本身中使用向量迭代器时,我遇到了编译错误

我试着从中执行这个例子,效果非常好。然而,当我试图把它放在一个函数中时,事情变得很糟糕,为什么会这样

vector <PointTwoD> topfive;
void MissionPlan::topfives()
{   
    topfive.assign( point1.begin(), point1.end() ); 
    sort(topfive.begin(), topfive.end(), sortByCiv);
}

void MissionPlan::DisplayTopFiveResult()
{
    missionplan.topfives();

    vector<PointTwoD>::iterator it = topfive.begin();
    for (int i = 0; i < 5 && it != topfive.end(); i++) {
    cout <<  "X axis: " << pointtwoD.xcord  << "          " << "Y axis: " << pointtwoD.ycord <<  "          " << "CIV Index: " << pointtwoD.civIndex << *it;
    ++it;
    }


}
向量前五名;
作废任务计划::topfives()
{   
赋值(point1.begin(),point1.end());
排序(topfive.begin()、topfive.end()、sortByCiv);
}
作废任务计划::DisplayTopFiveResult()
{
任务计划;
向量::迭代器it=topfive.begin();
for(inti=0;i<5&&it!=topfive.end();i++){
cout因为“值都在类
PointTwoD
中”

使用
it
打印以下内容:

vector<PointTwoD>::iterator it = topfive.begin();
    for (int i = 0; i < 5 && it != topfive.end(); i++) {
    cout <<  "X axis: "  << it->xcord  << " " 
         <<  "Y axis: "  << it->ycord  << " " 
         << "CIV Index: " << it->civIndex << std::endl;
    ++it;
    }
vector::iterator it=topfive.begin();
for(inti=0;i<5&&it!=topfive.end();i++){

cout@YuHao抱歉,我不知道,因为我被建议将此作为一个新问题发布,因为它使用的是另一种方法。现在有什么问题?你没有按照以前的帖子发布确切的问题?什么是
pointtwoD.xcord
pointtwoD.ycord
?看起来它应该打印相同的跳线,以及不同的
*它