Why this code doesnt work: error
this code is supposed to take a sentence, then swap first and last letters of each word and add "ay'' at the end of each word #include <iostream> #include <string> #include <vector> #include <sstream> int main() { std::string input; int last, first = 0; char r; std::cin >> input; std::istringstream iss{input}; std::vector <std::string> words; std::string word; while (iss >> word) words.push_back(std::move(word)); std::string aword, result; for (int i = 0; i < words.size(); i++) { aword = words[i]; last = aword.front(); first = aword.back(); r = aword[last]; aword[last] = aword[first]; //swap aword[first] = r; aword = aword + "ay"; if (i == 0) result = aword + " "; if (i == words.size() - 1) result = result + aword; else result = result + aword + " "; } std::cout << result; }