Reverse String C++ using char array

前端 未结 5 626
暖寄归人
暖寄归人 2020-12-03 01:52

I wrote a simple C++ program to reverse a string. I store a string in character array. To reverse a string I am using same character array and temp variable to swap the char

5条回答
  •  鱼传尺愫
    2020-12-03 02:37

    #include 
    #include 
    
    using namespace std;
    
    int main()
    {
        char str[80];
        cout << "Enter a string bro: \n";
        gets_s(str);
    
        for (int i = strlen(str) - 1; i > -1; i--)
        {
            cout << str[i];
        }
    }
    

提交回复
热议问题