I made this pig latin translator in c++ and I was wondering what I could improve and what is good about it. I used the stringstream class to get the individual words and I was also wondering how that works because I know what it does but I don’t know how it works. Thanks in advance.
#include <iostream> #include <vector> #include <sstream> std::string translate(std::string word){ if(word.length() > 1){ word += word[0]; word[0] -= word[0]; word += "ay"; } return word; } int main(){ std::vector<std::string> v; std::string str = "Hello the world has ended"; std::stringstream stringStream(str); for(int i = 0; i < str.length(); i++){ std::string currentWord; stringStream >> currentWord; v.push_back(currentWord); } for(int i = 0; i < v.size(); i++){ std::cout << translate(v[i]) + " "; } std::cout << std::endl; }