Hi,
I am trying to work out a simple code in C++.I am getting the input as a string and the output should be reversed.Some thing like this
input ="Glitters are Not gold"
output should be "gold Not are Glitters".

What i have done is get the string and stored it in a string variable and from there on i used Strrev().But its not working.Is there a good way of doing it.

Jegadees

You don't want to reverse the string, you want to reverse the words in the string. First you need to break up (parse) the string into substrings (words). But how are you going to know how many words there are and how will you know which order they are in once you get them separated out? Answer those three questions, or post code in an attempt to answer them (do one at a time!) and you should be well on your way to solving your problem.

Using the stringstream will make it easier. Or you can use substr as well, but will be more work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.