Answer to Question #188945 in C++ for zain ul abdeen

Question #188945

Q. write a program in c++ that display entered string into reverse order.


1
Expert's answer
2021-05-05T08:50:12-0400
#include <iostream>
#include <string>

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

    for(size_t i = 0; i < str.size() / 2; ++i)
    {
        char tmp = str[i];
        str[i] = str[str.size() - 1 - i];
        str[str.size() - 1 - i] = tmp;
    }

    std::cout << "Reversed string is:     " << str << "\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

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS