adding converted elements from vector

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        while(getline(threshold,readis,':'))
	{
		test.push_back(readis);	
	}
	for(int y=1; y<test.size(); y+=2)
	{
	if(test.empty())
	{
		cout<<"Your Vector is empty!!"<<endl;
	}
	else
	{
		s1 = strtod(test[y].c_str(), NULL);
		
		s2 += s1;
		cout<<s2;

		//cout<<vect.size();
	}
	}
original data from .txt file is

1
2
event1:21:event2:12:event3:89:event4:90:
event5:1:event6:9:event7:123:event8:67:


reason why my original vector is declared as string. then i converted the even positions into a double. now im not sure how to add them
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.

thanks thanks for the idea. i have made it work . much appreciated
Topic archived. No new replies allowed.