I need help to read words from a string

Hi, I need to read a word in a string, without using tokens.
Consider word as any sequence of letters that are uppercase or lowercase.
The numbers or other characters are not part of any word, but they separate words as if they were blank spaces.
For example, if the input is:

hola+Amigos2323 ,buenos(((di12--ASSS

The words extracted will be hola,Amigos,buenos,di and ASSS.

I tried

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

void cuentaPalabras(string frases,int &words){
   int l=0;
   int longitud=frases.length();

    do{
      
      if(frases[l-1]>64 && frases[l-1]<122 && frases[l+1]>64 && frases[l+1]<122 && frases[l]<64 && frases[l]>122){
	words++;
	l++;
      }
  
      else 
	l++;
      
    }while(l<longitud);

But doesnt works, any solution?
Last edited on
without using tokens.
This makes no sense. Give examples of what you're not allowed to do.
1
2
3
4
5
6
7
8
9
10
11
12
13
14

void cuentaPalabras(string frases,int &words){

istringstream ss (frases);

string tokenizado;

   while(getline (ss, tokenizado, ' , ' ) ){
      words++; 
   }


}

This is what Ive tried, but I cant use istringstream, so I think that I must be done with loops
Last edited on
Get whole line
Create vector<string> to hold all the output words
create empty string
for each character in the input line
{
if (character is a letter) {add it to the end of the current string}
else {push_back current string onto vector<string>, then clear the string}
}
Topic archived. No new replies allowed.