separate words with hyphen

Hi so I am trying to make a function that gets a string and returns two or more different words if they are separated by hyphens.
for example
input = some-thing
output = some thing (2 different words)

right now my function deletes the hyphens but returns them as one word.
any help is appreciated. thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
  string normalWord(string str)
{
	for (int i=0; i<str.length(); i++)
	{
		if(!((str[i]>='A' && str[i] <= 'Z')|| (str[i] >= 'a' && str[i] <= 'z'))) 
		{
			
			str.erase(i,1); 
			--i;
		}
	}
	return str;
}
Last edited on
If you want to return separate strings, why is the return type only one string? Hint: you will want to use a vector of strings instead ;)
Instead of erasing the hyphen, change it to a space?
@cire : i changed it to a space
 
str[i] = ' ';

but it returns 'something' as one word.

@L B : if i use a vector of strings, how would i access the letters after the hyphens?
What do you mean? Each word would be an element in the vector, with no spaces or hyphens involved.
Topic archived. No new replies allowed.