HI I have a program that reads in a .txt file and saved in a vector. now i need to add those integers that is in the even position. Since my vector is declared as a string cos my column1 is a string , only column 2 is a double. I had to convert if which i have already done. now my question is it seems like when i converted it it took the data as one number so im not sure how to add my elements.
HI I have a program that reads in a .txt file and saved in a vector. now i need to add those integers that is in the even position. Since my vector is declared as a string cos my column1 is a string , only column 2 is a double.
So why didn't you use a vector of struct or class that has the proper types to hold the information from your file. By the way looking at your file it appears to me that the second field is an int not a double.
1 2 3 4 5 6
struct whatever
{
std::string name;
int number;
};
Then just read the entire line into a string and then use a stringstream to process that line to fill in the structure then push that temporary structure into your vector.