Well, this is another classic puzzle... My goal is to take the first letter of each word in a string and put it at the end of that word adding -ay (Pig Latin). I managed to transform the first word. But how do I move on to the next? I consulted different sources, forums but I am still stuck... Any tips? :) Maybe something like: pos = a.find(" ", pos +1)? See code below:
#include <iostream>
#include <string>
int main()
{
std::string a = "hello what is going on";
std::string b = "ay ";
std::size_t pos = a.find(" ");
int length = a.length();
std::string first = a.substr(0,1);
for (int i = 0; i <= length; i++)
{
if (pos != std::string::npos)
{
a.replace(pos, a.length(), first + b); //I guess I have to change sth. here.
} //Maybe a while-loop?
}
a.replace(0, 1, "");
std::cout << a; //Output: "ellohay"; **goal**: "ellohay hatway siay oingay noay"
}