help me please

Member Avatar for jencas

Don't know if this is exactly what you mean:

include <string>
#include <string>
#include <iostream>

using namespace std;

void reverseStringWithLoop(string & str)
{
    size_t len = str.length();
    for (size_t i = 0; i < len / 2; ++i)
    {
        size_t j = len - i - 1;
        swap(str[i], str[j]);
    }
}

int main()
{
    string str("12"); // works with arbitrary string length
    reverseStringWithLoop(str); // same as std::reverse(str.begin(), str.end());
    cout << str;
    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.