首页 > 解决方案 > 从文件读取时将对象添加到向量中

问题描述

将由 , 分隔的 csv 文件添加到蛋白质对象时遇到问题。任何帮助将不胜感激。

   vector<Protein> proteins;
    
      Protein prot;
    
     // load disprot database of intrinsically disordered proteins
     std::ifstream reading;
     reading.open("C:\\Users\\james\\CLionProjects\\untitled1\\disprot.csv");
     std::string line, col;
     if (reading.is_open()){
         while (reading.good()){
    
             std::getline(reading, line);
             std::stringstream ss(line);
             while(std::getline(ss, col, ',')){
                Protein temp(ss.get(), ss.get(),ss.get(),col.get_allocator())
                proteins.push_back(prot);
             }
         }
            reading.close();
        }
         else if(!reading.is_open()) throw std::runtime_error("Could not open file");

标签: c++

解决方案


推荐阅读