How do you reverse a string in C/C++?
How do you reverse a string? In other words if I have "It is hot today", I want to get "today hot is It".
hmmm, sounds like you should read your text, perhaps post some code and then ask for some help. this might lead you in the right way:
#include%26lt;iostream%26gt;
#include%26lt;string%26gt;
int main()
{
using namespace std;
string txt;
cout%26lt;%26lt;"Enter anything, come on, anything...\n";
getline(cin,txt);
string::iterator end = txt.end( ) - 1;
for( ; end != txt.begin( ) - 1; end--)
{
cout %26lt;%26lt; *end;
}
cout %26lt;%26lt; endl;
system("pause");
return 0 ;
}
Reply:just reverse the string i guess
and in arrays if it from 1 to 5 it will count 12345 but if u reverse it as 5 to 1 , it will show 54321
good luck
Reply:Technically you are not reversing a string. You are reversing a subset of items inside a string.
So you would have to create an array of strings. Parse the contents of your original string by some separator, such as a space.
Then just reverse loop through the array of strings.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment