C++ 字串處理

[C++] 如何反轉字串 (How to Invert A String in C++)

The Problem:Your job is, inverting an input string,

Sample Input:abcde
Output:edcba

Here is an example to solve this problem in C++:

#include <iostream>
#include <string.h>
#define MAX_SIZE 256
using namespace std;

int main(){
    char input[MAX_SIZE];

    cout << "Input a String to inverse: ";

    cin.getline(input,MAX_SIZE);
    int input_Size = strlen(input);

    cout << "Before String inverse: " << input;

    for(int i = 0;i < input_Size/2; i++){
        char temp;
        temp = *(input+(input_Size-i-1));
        *(input+(input_Size-i-1)) = *(input+i);
        *(input+i) = temp;
    }

    cout << "After String inverse: " << input;
    return 0;
}