Answer to Question #188865 in C++ for Asad

Question #188865

Write a program to take an input string, store this string into another string in reverse order. Print the original and reversed string both.

 



1
Expert's answer
2021-05-05T14:27:03-0400
#include <iostream>
#include <string>

int main()
{
    std::cout << "Please enter an string: ";
    std::string source;
    std::getline(std::cin, source);

    std::string result;
    for(std::string::const_reverse_iterator iter = source.rbegin(); iter != source.rend(); ++iter)
    {
        result.push_back(*iter);
    }

    std::cout << "Original string: " << source << "\n";
    std::cout << "Reversed string: " << result << "\n";
    
    return 0;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS