我已經寫了代碼扭轉一個字符串倒車的字符串:無用值
#include <iostream>
#include <cstring>
using namespace std;
string Reversal(char * s);
int main()
{
char str[25];
cout << "Enter a Name :";
cin.get(str, 25);
cout << "You have entered: " << str;
cout << "\nReversed : " << Reversal(str);
return 0;
}
string Reversal(char * s)
{
int count = strlen(s);
char temp[count];
for (int i = 0; i < count; i++)
{
temp[i] = * (s + (count - 1) - i);
}
return temp;
}
都提到下面的鏈接,使CIN採取空格輸入:
但輸出顯示一些垃圾字符?任何建議爲什麼如此?