Damn I have been stuck on this function for hours trying to figure out why it won't decrypt a pig latin message into the original word.
This is just my function since the entire program is rather large. What happens is if my message is "ig-pay atin-lay" I end up with just "ati" instead of pig latin.
Two things, you have charPosition=charPosition on line 25 and the extraction operator is a horrible way of getting strings, use std::getline (std::istream,std::string) instead.
The only reason I use the extraction operator is because I haven't learned anything else yet really but I'll try to use what you stated. But wouldn't the getline grab all the strings? I just want to work with one string at a time.
About my second for loop.
The reason I put charPosition = charPosition is because I wanted the loop to start at the dash position and not back at 0. What am I supposed to use as my initalizer to keep the curser at that position?
The getline function will only get a line of text, so if all the strings are on the same line then it will get all the strings. So in this case the extraction would be better since it needs to be read in as a single word at a time.
To do what you want to do, you would need to break or store where the dash is in another variable, dashPosition and set charPosition to it in the for loop to start at that position.
The second parameter it's the length of the substring. So you must not do the decrease.
The reason I put charPosition = charPosition is because I wanted the loop to start at the dash position and not back at 0. What am I supposed to use as my initalizer to keep the curser at that position?
No need to do that. A variable doesn't change its value at least you told it to do it. (and you need to move 1 step actually)
In the loop for the prefix you aren't updating character.
1 2 3
if(cond){}
//if(!cond){}
else{} //note that the conditions are complementary
Also, just a preference, but try to not put so long names to index and aux variables. And keep your functions small (why not just pass the word to convert, instead to asking the function to read it from a file)
This function really twisted my brain around and I ended up learning the .find command to find specific characters.
So I set a variable for the dash and a variable for the "ay" after the dash if it was found to make sure I had a word in pig latin.
Then I took substrings from position 0 to the dash for the post fix and from the char after the dash to right before the "ay" as the prefix and just added them togethor to get the original word back.
And if a dash and proceeding "ay" weren't found I just sent the word straight through since it obviously wasn't a pig latin word unless it happened to be a freakish word that had a dash and ay after it. haha
My prof wasn't worried about that.
But shit, coding is tough man. This is only my second programming class and I have spent more time working on this class alone than all my other 4 combined!