reversing a string

teddy13 0 Tallied Votes 380 Views Share

here is code for reversing a string

#include<iostream>
#include<string>
using namespace std;
int man(){
	string s;
	cout<<"Type something...\n";
	getline(cin,s);
	string::iterator pos;
	for(pos=s.end();pos!=s.begin()-1;pos){
	out<<*pos;
	}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The code does not even compile. Please verify that the code works before posting it. Next time such imcomplete codes will be deleted...

This time I am ediiting so that it just works..

#include<iostream>
#include<string>
using namespace std;

int main()
{
    string s;
    cout<<"Type something...\n";
    getline(cin,s);
    string::iterator end = s.end( ) - 1;

    for( ; end != s.begin( ) - 1; end--)
    {
        cout << *end;
    }
    return 0 ;
}
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.