I have a vector of a class holding codons, amino acids, names, and molar masses.
Molar mass is type string right now but I need to change it to type float or double so I can add up all the values.
All the variables that are in the vector were read in from a file.
Not sure what you're trying to show with the vector there, but if you want to convert a string literal or std::string into a double, I would suggest using std::stringstream.
Thanks, I wanted to show how my vector took in the variables to make better sense of the problem. So I need the molar masses to become a vector. So I should use std::stringstream?
Yes, so in your case you could do something like this, if I'm understanding correctly:
1 2 3 4 5 6 7 8 9 10 11
/// in loop:
fin >> fullname;
fin >> threeLetter_name;
fin >> molarMass;
fin >> codons;
double molarMass_num;
// stores the string as a number into molarMass_num:
std::stringstream(molarMass) >> molarMass_num;
AminoAcid tempC(fullname,threeLetter_name, molarMass_num, codons);
Note using stringstream requires the header <sstream>
However, you don't do anything else with molarMass, why not just stream it from the file as a double to begin with?