Apr 11, 2015 at 7:55am UTC
write a code to reverse words of a string. please do it in the simplest way it will help to understand.......
Apr 11, 2015 at 8:08am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
std::string reverse_string(std::string s)
{
int start=0, stop=s.size()-1;
while (start<=stop)
{
char temp=s[start];
s[start]=s[stop];
s[stop]=temp;
++start; --stop;
}
return s;
}
i guess that would help.
Last edited on Apr 11, 2015 at 8:09am UTC
Apr 11, 2015 at 9:06am UTC
Note that the code posted by Andy also reverses the order of the words in the string.
Apr 11, 2015 at 9:14am UTC
@peter i agree, @Sazzad sorry i din't take my time to think about the question, about reversing the words in a string is a different thing from what i gave , i'll edit my post to take care of words.
Apr 11, 2015 at 9:28am UTC
This is probably homework so it might be better if you don't give him the complete solution.
Apr 12, 2015 at 4:36pm UTC
dear it is not a assignment or home work.if it was thn i will try it by myself :)