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

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

Sample Input:abcde

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: ";

    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;


發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *