Solution: Reverse a String

Naive

#include <string>
#include <iostream>

using namespace std;



int main()
{
    string s;
    cin >> s;

    string reversed_s;

    for (int i=s.size()-1; i>=0; i--)
        reversed_s += s[i];

    cout << reversed_s << endl;

    return 0;
}

Using std::reverse<>

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

using namespace std;


int main()
{
    string s;
    cin >> s;

    std::reverse(s.begin(), s.end());

    cout << s << endl;

    return 0;
}

Using std::reverse_copy<>

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

using namespace std;


int main()
{
    string s("abc");

    string reversed_s(s.size(), '*');
    std::reverse_copy(s.cbegin(), s.cend(), reversed_s.begin());
    cout << reversed_s << endl;

    return 0;
}
cluster_cxx03 C++ cluster_cxx03_stl Standard Template Library cluster_cxx03_stl_exercises STL: Exercises cluster_cxx03_stl_exercises_reverse_string Exercise: Reverse A String cluster_cxx03_stl_algorithm Algorithms cluster_cxx03_exceptions Exceptions cluster_cxx03_data_encapsulation Data Encapsulation cluster_cxx03_templates C++ Template Basics cluster_c The C Programming Language cluster_c_introduction Introduction cxx03_introduction Introduction c_introduction_installation Installation cxx03_introduction->c_introduction_installation cxx03_stl_basics Standard Template Library: Basics cxx03_templates_class_templates Class Templates cxx03_stl_basics->cxx03_templates_class_templates cxx03_stl_exercises_reverse_string_solution Solution: Reverse a String cxx03_stl_exercises_reverse_string_exercise Exercise: Reverse a String cxx03_stl_exercises_reverse_string_solution->cxx03_stl_exercises_reverse_string_exercise cxx03_stl_algorithm_reverse_copy reverse_copy<>: Copying and Reversing cxx03_stl_exercises_reverse_string_solution->cxx03_stl_algorithm_reverse_copy cxx03_stl_algorithm_reverse reverse<>: Reversing In-Place cxx03_stl_exercises_reverse_string_solution->cxx03_stl_algorithm_reverse cxx03_stl_algorithm_reverse_copy->cxx03_stl_basics cxx03_stl_algorithm_reverse->cxx03_stl_basics cxx03_exceptions_basics Basics cxx03_exceptions_try_catch try - catch cxx03_exceptions_try_catch->cxx03_exceptions_basics cxx03_data_encapsulation_classes_objects Classes and Objects cxx03_exceptions_try_catch->cxx03_data_encapsulation_classes_objects cxx03_data_encapsulation_classes_objects->cxx03_introduction cxx03_data_encapsulation_c Object Oriented Programming In Good Ol’ C cxx03_data_encapsulation_classes_objects->cxx03_data_encapsulation_c cxx03_data_encapsulation_c->cxx03_introduction cxx03_templates_function_templates Function Templates cxx03_templates_function_templates->cxx03_exceptions_try_catch cxx03_templates_class_templates->cxx03_templates_function_templates