C++ Code To Reverse A String:


C++ Code To Find The Reverse Of  String
===============================

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

int main()

{
    std::cout << "%%%%%%%%%%%%%%%%%%String Reversing App%%%%%%%%%%%%%%%%%%%%%%%%\n\n";

    std::cout << "\nEnter 1 to continue and 0 to exit" << std::endl;
    int inputa;
    std::cin >> inputa;
    if(std::cin && inputa!=0)
    {
        std::cin.ignore(std::numeric_limits<int>::max( ), '\n');
        do
        {
            std::string a,c;
            std::cout<<"\nEnter the string you want to Reverse : ";
            getline(std::cin, a);
            for(int x=a.length()-1; x>=0; --x)
            {
                c+=a[x];
            }

            std::cout<<"\nThe Reverse String is : " << c << std::endl;
            std::cout << "\nEnter 1 to continue and 0 to exit" << std::endl << std::endl;
            std::cin >> inputa;
            std::cin.ignore(std::numeric_limits<int>::max( ), '\n');
        }
        while(std::cin && inputa!=0);
    }
}

No comments:

Post a Comment