Trying to get the below code to reverse the entire input but it is only reversing the first word.
============================================
void Reverse(string &theSentence);
int main(void)
{
string MySentence;
cout << "Enter a Sentence to be reversed: ";
cin >> MySentence;
cout << "Before Reverse:" << endl;
cout << " MySentence = " << MySentence << endl << endl;
Reverse(MySentence);
cout << "After Reverse:" << endl;
cout << " MySentence = " << MySentence << endl << endl;
_getch ( );
return(0);
}
void Reverse(string &theSentence)
{ // Reverse the string contained in theSentence.
int i;
char temp;
for (i=0; i<theSentence.length()/2; i++)
{
temp = theSentence[i];
theSentence[i] = theSentence[theSentence.length()-i-1];
theSentence[theSentence.length()-i-1] = temp;
}
}
cin >> MySentence;
cin >> stops at whitespace.
If you want to get the whole line, use getline:
getline(cin,MySentence);