C++ Strings
I don't yet have a clear understanding of how to use the string class yet.
i'm stuck as how to get started. I have this program that wants you to use find, length and substr without any type of loop or switch to convewrt a string into it's pig latin equivalent. Assume the vowels are e i o u and you are to check for the irst occurence of a vowel if the first letter has vowel add way to the end otherwise continue checking for the first occurence of a vowel and if found move the letters to the end and add ay to the end.
for example: apple = appleway
strong = ongstray
Any help would greatly be appreciated
i'm stuck as how to get started. I have this program that wants you to use find, length and substr without any type of loop or switch to convewrt a string into it's pig latin equivalent. Assume the vowels are e i o u and you are to check for the irst occurence of a vowel if the first letter has vowel add way to the end otherwise continue checking for the first occurence of a vowel and if found move the letters to the end and add ay to the end.
for example: apple = appleway
strong = ongstray
Any help would greatly be appreciated
0
Comments
(http://www.cplusplus.com - great place to learn standard functions)
edit:// this only works on single words btw, in order to make it work with sentences, use the same chopper code in a simple loop, and chop on " " (check the link for how to do this) and then pass each delimited string to the vowel check seperately.
m
If it finds the letter you are looking for with the .find function it will return the index of the letter. Now you have to use the .substr from 0 to that index value returned to take off the front of the string and you can store that in a temporary string.
Use the index for the vowel and substring again to get the final part of the word and store that in another temporary string.
Finally, you can use + or .strcat to add the strings together and tack on the "way".
for example say you have this:
int main()
{
string word;
int pos;
int position;
cout << " Enter A Word: ";
cin >> word;
pos = word.find("a");
if (pos != string::npos)
position = pos;
pos = word.find("e")
if(pos != string::npos)
if(pos < position)
position = pos;
}
this is the problem, it bombs once this is working i can use substr to chop the preciding letters off that are in front of the vowel i find.
cplusplus.com and the MSDN website can help you out.