使用地图存储已读取的数据?

时间:2018-12-07 14:09:09

标签: c++ dictionary stl

大家好,谢谢您抽出宝贵的时间阅读本文。因此,基本上,我试图将通过文本文件读取的数据存储到:      std::map<double,pair<double,double>>storage 第一个双精度数表示坐标的ID,而一对则表示x和y值,则可以忽略z值。

ID X Y Z / n ID X Y Z

顶点类

class vertex
   {
   public:

        map<double,pair<double,double>> keyTable;
        int count = 0; // just temporary to count the number of lines
        ifstream filestuff; //used later to initialize the reference

        double vert_id; //The ID of the Vertex will be stored here
        int num_vert,num_attrib,num_dimen; //First line of the .tri file
        //Declare class as a friend to take the ifstreamed file from main
        friend ifstream& operator >> (ifstream& input, vertex &vert){
            input>>vert.num_vert>>vert.num_dimen>>vert.num_attrib;
            return input;
        }
    vertex();
    virtual ~vertex();
    protected:
    private:
    double x,y,z; // Coordinate points
 };

在构造函数中

 vertex::vertex(){

    ifstream& input = filestuff; // text file passed as a reference

    while (getline(filestuff, line)) {
        count++

        while (count<num_vert) // for loop to stop at a
        {
        //add to the map and pray to god its okay
        keyTable.insert(?);
         // MAP STORED AS KEY = ID and pair of points is X and Y
        }      


      }

    return;
        //ctor
 }

0 个答案:

没有答案