Thanks for the swift reply MiiNiPaa, I know it must be frustrating for someone skilled like yourself, but is there perhaps a way you could explain a little more?
I have basic c++ knowledge and I know that I have to use substrings (so I have read at least)
I am trying to reverse every other word in the sentence, eg-
"The mouse was caught in the peg"
So "mouse" "caught" "the" would need to be reversed and then output into the full sentence but with the even words reversed, if there are any tutorials etc I would be happy to follow them.
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
int main()
{
std::string original = "The mouse was caught in the peg";
//http://en.cppreference.com/w/cpp/io/basic_istringstream/basic_istringstream
std::istringstream in(original);
std::ostringstream out;
std::string word;
int i = 0;
while(in >> word) {//Read next word in sentence
++i;
if(i % 2 == 0) //on each even word
//http://en.cppreference.com/w/cpp/algorithm/reverse
std::reverse(word.begin(), word.end()); //reverse word
out << word << ' '; //Add word to new sentence
}
std::string modified = out.str();
std::cout << original << '\n' << modified;
}
The mouse was caught in the peg
The esuom was thguac in eht peg
Ah it makes much more sense now! Thanks for the reply! Finally how would I go about modifying it so that the user could input the sentence rather than hard coded?