Here you go:
#include <string>
#include <iostream>
#include <stack>
int main(void)
{
std::string s;
std::cout << "Enter the sentence: " << std::flush;
std::stack<std::string> ss;
do
{
std::cin >> s;
ss.push(s);
} while (std::cin.peek() != '\n');
while (!ss.empty())
{
std::cout << ss.top() << ' ';
ss.pop();
}
std::cout << std::endl;
}
Test run:
Enter the sentence: this is yahoo group
group yahoo is this
Shyan
> -----Original Message-----
> From: sravani33 [mailto:[EMAIL PROTECTED]
> Sent: Thursday, December 02, 2004 3:29 PM
> To: [EMAIL PROTECTED]
> Subject: [C-Paradise] reverse words of a string
>
>
>
> Hi all,
>
> write a program to reverse the words of a sentence. for ex
> if you give input , "this is yahoo group"
> the result shoud be "group yahoo is this"
>
> thank you
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~->
>-----------------------------------------~-~>
CHECK THE ARCHIVE BEFORE POSTING!!!! Archive is available at
http://www.eScribe.com/software/C-Paradise/
>------------------------------------------_->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/C-Paradise/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/