Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
83 views
in Technique[技术] by (71.8m points)

c++ - Adding objects into vectors when reading in from a file

Having issues with adding a csv file seperated by , into a protein object. Any help would be greatly appreciated.

   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");
question from:https://stackoverflow.com/questions/65831116/adding-objects-into-vectors-when-reading-in-from-a-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...