Is there a way to grab a string from a string vector and split it in to individual character so i can check weather they are numbers or letters?
I want to do this so i can get a string like "12as 32312dsda sda23asd" and turn it in to individual strings in a vector and then check weather its a number or letter, then add the 3 numbers or more up. like 12 +32312 + 23=.....
so far i just have the string separated in to separate strings in a vector.
[code]
void readData(ifstream& in, double& sum, int& count)
{
double tempSum = double();
string line;
string word;
int score;
int length;
int i = 0;
int k = 0;
getline(in, line); //takes line from in and puts in string line
istringstream iss(line); //takes whole line and turns in to indv strings
vector< string > words((istream_iterator<string>(iss)), istream_iterator<string>());
while (i < words.size())
{
cout << words[i]; //print vector element
i++;
}
}
I can parse a normal string and see if the char is a digit with something like:
int i = 0;
if(i < line.length())
{
if (isdigit(line[i]))
{
cout << line[i] << endl;
i++;
}
}
but how do i call a string from a vector and preform the same check and do it till i read all the words from the string?
I want to do this so i can get a string like "12as 32312dsda sda23asd" and turn it in to individual strings in a vector and then check weather its a number or letter, then add the 3 numbers or more up. like 12 + 32312 + 23=.....
In other words, can you tell us what this string will become :
"12as 32312dsda sda23asd"?
basically i split "12as 32312dsda sda23asd" in to separate string words: "12as" "32312dsda" "sda23asd" and put them in a vector. I am asking how i call the data from the vector, split each letter from the word string and then test each letter to see if the letter is a number and if it is hold it and after it found all the numbers in the word string it would combine them. like the word string 12as would become the int 12, or sda23asd would become 23.