0

動作する頂点のリストを取得しました。今、各頂点にエッジを入れようとしていますが、隣接する頂点を元の頂点リストのエッジに入れようとするとうまくいきません。イテレータを使用してエッジの始点にある頂点を見つけ、別のイテレータを使用してエッジ (通り) の終わりにある頂点を見つけます。何らかの理由で、エッジの頂点ポインターを頂点リスト内の要素に設定しようとすると、許可されません。エラー「エラー 1 エラー C2679: バイナリ '=' : タイプ 'std::_List_iterator<_Mylist>' の右側のオペランドを取る演算子が見つかりません」:

主要:

#include<iostream>
#include<list>
#include <fstream>
#include<cmath>
#include <cstdlib>
#include <string>
#include<sstream>
#include "global.h"
#include "edge.h"
#include "vertex.h"
using namespace std;

int main ( int argc, char *argv[] ){
if(argc != 4){
    cout<< "usage: "<< argv[0]<<"<filename>\n";
}
else{

    ifstream map_file (argv[3]);

    if(!map_file.is_open()){
        cout<<"could not open file\n";
    }
    else{
        Edge tempe;
        Vertex tempx;

        std::string line;
        std::ifstream input(argv[3]);
        int xsect;
        int safety;
        int change = 0;
        int i = 0;
        int vert = 0;
        int adjvert = 0;
        int dist = 0;
        //k and m keep track of iteration through list
        int k = 0;
        int m = 0;
        std:string xname;

        std::list<Vertex> xSectionList;
        std::list<Edge> EdgeList;




        while (getline(input, line))
        {

          std::istringstream iss(line);
          if(line == "INTERSECTIONS:"){
              change =1;
              i = 0;
          }
          else if(line == "STREETS:"){
              change = 2;
              i = 0;
          }

          if( change ==1 && i != 0){
            iss >> xsect >> safety;

           std::getline(iss, xname);

           tempx.xsect = xsect;
           tempx.danger = safety;
           tempx.xstreets = xname;

           xSectionList.push_back(tempx);

          }

         else if(change ==2 && i!=0){ 

                iss >> vert >> adjvert >> dist;


              std::list<Vertex>::iterator it = xSectionList.begin();

              while(it->xsect != vert || k != xSectionList.size()+1) {
                it++;
                k++;
             }

              std::list<Vertex>::iterator tit = xSectionList.begin();

              while(tit->xsect != adjvert || m != xSectionList.size()+1) {
                tit++;
                m++;

             }

              //tempe.adjvertex = tit;
              tempe.distance = dist;
              it->EdgeList.push_back(tempe);
              it->EdgeList.begin()->adjvertex = tempx;
               //std::getline(iss, xname);
              }

           //cout<<xsect<< " " << safety << " " << xname<<endl;

          i++;
        }



        std::list<Vertex>::iterator kit = xSectionList.begin();
        std::list<Edge>::iterator lit = kit->EdgeList.begin();

        //std::cout << it->xsect<< " " << it->danger << " "<< it->xstreets;

        for(lit = kit->EdgeList.begin(); lit != kit->EdgeList.end(); lit++) {
            cout << kit->xsect << "" << lit->adjvertex->xsect << "" << lit->distance<< endl;
         }


        }
    }

getchar();
}

ヘッダ頂点`

#ifndef VERTEX_H
#define VERTEX_H
#include<list>
#include<string>
#include "global.h"

struct Vertex_{
int xsect;
int danger;
std::string xstreets;

std::list<Edge> EdgeList;
/*struct Vertex_ *next;
struct Vertex_ *prev;*/
};

#endif

エッジ ヘッダー

#ifndef EDGE_H
#define EDGE_H

#include "global.h"
#include "vertex.h"
struct Edge_{
Vertex *adjvertex;
int distance;

/*struct edge *next;
struct edge *prev;*/
};

#endif

ファイルの例 交差点が頂点で、道路がエッジである場所からデータをスキャンしています:

397 0.6 Drachman and 27th
398 0.5 Drachman and 28th
399 0.3 Drachman and 29th
400 0.8 Drachman and 30th

STREETS:
1   2   0.5
2   3   1.0
3   4   0.9
4   5   0.7
5   6   0.1
4

2 に答える 2

0

イテレータはポインタのように機能しますが、通常はポインタではありません。あなたは次のようなことをする必要があります

tempe.adjvertex = &*tit;

*titイテレータが現在存在する頂点を&*tit取得するため、その頂点へのポインタを取得します。

于 2012-12-05T03:56:16.937 に答える
0

これが宿題でない限り、ブーストグラフを使用します。

于 2012-12-05T04:18:56.360 に答える